I am trying to override the default validation css class for validators which is “field-validation-error” class
So, if I write a Validation message for a input on my form as below:
@Html.ValidationMessageFor(m=>m.Name)
Then the MVC runtime is setting the class of the message span by default as below:
<span class="field-validation-error" data-valmsg-replace="true" data-valmsg-for="Name">
My question is, how can I remove the css class “field-validation-error” and replace it with another class (my version) which i will be using it in only some areas of my application.
Ok…so I got it working by setting the base “field-validation-error” class as “form .field-validation-error” in the root css file…which means that this class will have the highest priority when the Html is generated and then in my View I included the new css class as mentioned below:
This will generate the below markup:
As you can see the NewCssClass will override the default validation style specified in the “field-validation-error” class…
Cheers…