如何在MVC Razor视图中使用带有多个输入的内联模板

时间:2012-10-03 21:18:40

标签: asp.net-mvc-3 razor

在我的观点中,我目前有

@{
    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表达式可以接受节标题的第二个输入?

1 个答案:

答案 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> 
    }