![](/img/trans.png)
[英]Custom Html Helper is not becoming avaliable in the View (Razor/Asp.Net MVC3)
[英]Custom Helper in 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<ToolBarAction>
。
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<IList<ToolbarAction>> addActions)
{
var menuActions = new List<ToolbarAction>();
addActions(menuActions);
var htmlOutput = new StringBuilder();
htmlOutput.AppendLine("<div id='menu'>");
foreach (var action in menuActions)
htmlOutput.AppendLine(html.ActionLink(action.Text, action.Action, action.Controller, new { @class = action.Name }).ToString());
htmlOutput.AppendLine("</div>");
return new MvcHtmlString(htmlOutput.ToString());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.