在我的观点中,我目前有
@{
Func<Website.Security.User[], object> renderUserList = @<text>
<div class="span4">
@*<h2>@title</h2>*@
<ul>
@foreach (var user in item)
{
<li>@user.UserName - <a href="/Config/User/Edit/@user.UserName">Edit</a></li>
}
</ul>
</div>
</text>;
}
@renderUserList(Model.AdminUsers)
我如何重做这个,以便renderUserList表达式可以接受节标题的第二个输入?
答案 0 :(得分:5)
据我所知,你试图创建帮手:ASP.NET MVC 3 and the @helper syntax within Razor
@helper renderUserList(Website.Security.User[] users, string title)
{
<div class="span4">
<h2>@title</h2>
<ul>
@foreach (var user in users)
{
<li>@user.UserName - <a href="/Config/User/Edit/@user.UserName">Edit</a></li>
}
</ul>
</div>
}