ASP.NET MVC 5 - Custom html controls

729 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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...