Asp.net mvc3中的自定义助手
我有一个ASP.NET MVC3应用程序。 我想要一个自定义工具栏,我希望在每个表单中显示。 这个自定义工具栏可以有一个或多个动作链接。所以,我需要开发一个自定义Html帮助器,我可以使用如下;
@Html.CustomToolBar(items => { items.Add("Action","Controller","Name","Text"); items.Add("Action1","Controller1","Name1","Text1");})
这个自定义扩展将生成链接html,我将在我的表单上显示它。 我有一个ToolBarAction
类,我想从@Html.CustomToolBar
获取List
。
public class ToolbarAction { public string Name { get; set; } public string Action { get; set; } public string Controller { get; set; } public string Text { get; set; } }
你能告诉我如何实现这个目标吗? 如果你能指出适当的资源,那真的很棒..
非常感谢
问候..
像这样的东西(我不知道Name属性是什么,所以我把它添加为类):
public static class HelperExtensions { public static MvcHtmlString Menu(this HtmlHelper html, Action> addActions) { var menuActions = new List(); addActions(menuActions); var htmlOutput = new StringBuilder(); htmlOutput.AppendLine(" "); return new MvcHtmlString(htmlOutput.ToString()); } }