views:

130

answers:

2

Is it possible (and how) to customize the HTML output of the HtmlHelper.ValidationMessage extension method in Asp.net MVC?

+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
Exactly what I just did. Had to copy original code (+2 privates) and built my own code.
Robert Koritnik
+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
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
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