asp.net-mvc-5asp.net-customcontrol

ASP.NET MVC 5 - Custom html controls


i would like to create custom html controls or form control. I can not find tutorial for it. I would like to create new controls or override existing form control. For example - override button and add icon into button.

Thanks


Solution

  • It is not the solution to my problem. I dont want write this:

    @using (Html.BeginForm("ActionTaken", "TestController"))   {
      <button name="button" value="ActionOne" class="button" style="width: 200px;">
         <img src=""/></button>
      <button name="button" class="button" style="width: 160px;" value="ActionTwo">
      <img src=""/></button>             }
    

    But I want to write something like:

    @Html.ButtonWithImage()
    

    Of course i can create HtmlHelper extension, but my question was whether it is done button class, something like:

    class MyButton : Control{
      public string Icon{get; set;}    
      public void Render()
      {
      }
    }
    

    or better still to be MyButton child of Html Button. I would expand on it icon and override render method...