0

I have used html helpers in mvc but i am confused that which could be the scenario where i would need to make custom html helpers in mvc , i have browse over the web and found the following :

here if the value of ImageSource,Imagename,ImageDescription will be null than view will throw error so by using custom html helper for the same we could get rid from conditional code and use our own custom helper method . but is that only reason to make custom html helpers what could be other scenario to use custom html helpers?

Parekh
  • 13
  • 1
  • 1
    For any time you want to generate generate valid html for a property, class or collection. A simple case might be `@HtmlReadonlyTextBoxFor(m => m.MyProperty)` to generate a textbox where the `readonly` attribute is set, to a complex case such a `@Html.TableDisplayFor(m => m.MyCollection)` that might render a table for all properties in the collection including headers an footers. –  Aug 13 '14 at 22:34

1 Answers1

0

There're many uses for html helpers, one use for example could be to create a helper which creates a

<a class='myClass' href='mysite/abc'><img src='myImg' /></a>

which you'd call as

Html.MyImgA("myClass", "abc", "myImg")

More in depth search over the internet will give you other ideas.

artm
  • 8,554
  • 3
  • 26
  • 43