Razor HtmlHelpers with sub-sections?
问题 Is there a way to build the custom Html Helpers and put them into sub-sections? I.e: @Html.Buttons.Gray @Html.Buttons.Blue @Html.Tables.2Columns @Html.Tables.3Columns Thanks. 回答1: Helpers are simply extension methods. So you could create helpers that return object that allow you to chain method calls, e.g. @Html.Button("Text").Grey() . public ButtonHelper { public string Text {get; set;} public MvcHtmlString Grey() { return MvcHtmlString.Create("<button class='grey'>"+ Text +"</button>"); } }