Is there a way to nest templates in the Razor view-engine such like this in the older Asp.net viewengine? For as much as i am aware Razor only supports one level of templates.
-John
<%Html.Do(new string[]{"Chris"开发者_开发知识库,"John"}, name =>
{
%>
<li><%=name%></li>
<%Html.Do(new string[]{"Beer","Fries"}, stuff => {
%>
<li><%=stuff%></li>
<%
}); %>
<hr size=1 />
<%
}
); %>
Change your function to take a Func<T, HelperResult>
, then pass @<li>@item</li>
EDIT: For example:
public static IHtmlString Do<T>(this HtmlHelper html, IEnumerable<T> items, Func<T, HelperResult> template) {
return html.Raw(String.Join("\n", items.Select(o => template(o).ToString())));
}
In Razor:
@Html.Do(new []{"Beer","Fries"}, @<li>@item</li>)
精彩评论