1

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Exactly what I just did. Had to copy original code (+2 privates) and built my own code.
yuck... I was afraid of this.
1

ASP.NET MVC 2 will provide the ability to customize the message. For ASP.NET MVC 1.0, Kurt's solution does the trick.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.