更新时间:2022-12-30 21:17:12
像这样的东西(我不知道什么名称属性是,所以我加了它作为类):
Something like this (I didn't know what the Name property was for, so I added it as the class):
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());
}
}