asp.net-mvc-5 Create a simple helper - a div with a text in it


Example

public static class MyHelpers 
{
   public static MvcHtmlString MyCustomDiv(this HtmlHelper htmlHelper, string text,
          object htmlAttributes = null)
   {
        var mainTag = new TagBuilder("div");
        mainTag.MergeAttributtes(htmlAttributes);
        mainTag.AddCssClass("some custom class");
        mainTag.SetInnerHtml(text);
        return MvcHtmlString.Create(mainTag.ToString());
   }
}

To use it in the views:

@Html.MyCustomDiv("Test inside custom div");
@Html.MyCustomDiv("Test inside custom div", new {@class="some class for the div element"});