ASP.NET MVC – Replace label with validation error message? – Education Career Blog

I’d like to highlight field names instead of showing a separate error message when there is a validation error.

Is there any convenient way of doing this other than checking the ModelState Errors collection and wrapping each .LabelFor() in an if?

Also, I’d like to format labels as either bold, or add an asterisk if the model metadata has a Required attribute.


You’ll need use a custom Object.ascx file by creating either /Shared/DisplayTemplates/Object.ascx or /Shared/EditorTemplates/Object.ascx

I can’t answer any better than this guide at Brad Wilson’s blog:

Leave a Comment