Jonas Stawski

Everything .NET and More

ASP.NET MVC3 change validation class

If you are using the ASP.net MVC3 built in validation such as

   1: @Html.ValidationMessageFor(m => m.Username)

you can easily change the validation by overriding the CSS class field-validation-error like this:

   1: .field-validation-error
   2: {
   3:     color: red;
   4: }
   5:  
   6: .validation-summary-errors
   7: {
   8:     color: Red;
   9: }

The CSS above is the one used for the span that will contain the invalid error message for the specific field and for the validation. furthermore, you can bring more attention to the input that caused the error by adding a class like this (please note this one only works with inputs):

   1: input.input-validation-error
   2: {
   3:     background-color: orange;
   4: }

Happy programming!

Comments (4) -

Nice to know. Thanks !

Reply

abdul quadir siafee
abdul quadir siafee

but how to change default validation message

Reply

@abdul, you can read this article for more details on unobstruviste validation in MVC 3: weblogs.asp.net/.../...ation-in-asp-net-mvc-3.aspx" title="weblogs.asp.net/.../...ation-in-asp-net-mvc-3.aspx">weblogs.asp.net/.../...ation-in-asp-net-mvc-3.aspx

Reply

niceeeeeeeee..........

Reply

Add comment

biuquote
Loading