Is it possible (and how) to customize the HTML output of the HtmlHelper.ValidationMessage
extension method in Asp.net MVC?
views:
130answers:
2
+1
A:
Other than passing in some html attributes, you will have to roll your own extension method if you need full customization (for example, to have it render as a <div>
instead of <span>
)
I would copy the ValidationMessage method from the mvc source code and customize it as needed.
Kurt Schindler
2009-10-28 21:36:49
Exactly what I just did. Had to copy original code (+2 privates) and built my own code.
Robert Koritnik
2009-10-28 22:03:15
+2
A:
ASP.NET MVC 2 will provide the ability to customize the message. For ASP.NET MVC 1.0, Kurt's solution does the trick.
Haacked
2009-10-28 23:32:30
That's nice to hear. But it's will still probably just be able to customize HTML element... It would be best to customize even more complex HTML creation. For instance I have a DIV with a child DIV. Child DIV displays the message... Anyway. MVC2 probably won't be configurable to this level, will it?
Robert Koritnik
2009-10-29 17:02:16
You'll be able to have any custom HTML markup you want. If you choose this approach, we'll simply toggle the visibility of the message via a CSS class. So yes, you'll be able to do this.
Haacked
2009-10-29 23:01:05