Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC2 Html.ValidationMessageFor: add htmlAttributes but keep the default message

I would like to change the htmlAttributes of the code rendered by my Html.ValidationMessageFor, but I want the message displayed to be the "default".

The overload options are:
A) Html.ValidationMessageFor(expression)
B) Html.ValidationMessageFor(expression, validationMessage)
C) Html.ValidationMessageFor(expression, validationMessage, htmlAttributesObject)

I wish there was a Html.ValidationMessageFor(expression, htmlAttributesObject) option, but there is not.

How can I achieve the desired result with option C? That is, where is that "default" messages stored? Is there an clean, easy way to get at it, so I can plug it in to the validationMessage parameter?

Thanks

like image 595
Carson Herrick Avatar asked Oct 15 '10 14:10

Carson Herrick


1 Answers

Since you don't want to override the default message, simply supply an empty string and MVC will use the default message:

<%: Html.ValidationMessageFor(m => m.propertyName, string.Empty, new { attribs ... }) %>
like image 191
Clicktricity Avatar answered Oct 17 '22 21:10

Clicktricity