HtmlHelpers to help

HtmlHelpers are nice and easy. They just return a string with html and accepts the object you send as parameter. Default there are the followin HtmlHelpers available:

  • Html.ActionLink()
  • Html.BeginForm()
  • Html.CheckBox()
  • Html.DropDownList()
  • Html.EndForm()
  • Html.Hidden()
  • Html.ListBox()
  • Html.Password()
  • Html.RadioButton()
  • Html.TextArea()
  • Html.TextBox()

It's easy to create your own Html Helpers, example of a HtmlHelper wich accepts a list of strings and returns this in Html, in this case in spans

    public static class RapportHelper
        public static string RenderDimensions(this HtmlHelper helper, List dimensions)
            string result = string.Empty;

            foreach (var item in dimensions)
                result += "" + item +"
"; } result += "
"; return result; } }

Now you can use this helper in the view, example of using it in a Webgrid:

                    grid.Column(header: "Verwijder",format: @<text><a href="#" class="RapportDelete" rel="@item.RapportId">-</a></text>) ,
                    grid.Column(header: "Edit",format: @<text><a href="#" class="RapportDetail" rel="@item.RapportId">+</a></text>) ,
                    grid.Column( "Rapportnaam", "Rapportnaam", canSort:true ),
                    grid.Column( "KlantId", "KlantId", canSort:true ),
                    grid.Column( "RapportType", "RapportType", canSort:true ),
                    grid.Column( "DimensionsList", "DimensionsList", canSort:false, format: (item) => @Html.Raw(@Html.RenderDimensions((List<String>)item.DimensionsList))),
                    grid.Column( "MetricsList", "MetricsList", canSort:false, format: (item) => @Html.Raw(@Html.RenderDimensions((List<String>)item.MetricsList)))





Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!