I have created a new asp.net mvc-5 web application using VS 2013. now when i try the built-in login form and i leave the required fields empty i got the following, :-
where both fields were not highlighted with red color as i use to get inside previous versions of asp.net mvc. now from the generated markup i can inspect that any field that have validation errors will have the following class:-
input-validation-error
But i search the whole css files which are generated automatically inside my asp.net mvc-5 web application mainly; site.css , bootstrap.css bootstrap.min.css , but i could not find a definition for the input-validation-error ?? so can anyone advice on this please, how i can highlight the fields with red color if they have validation error , and why this is not the default behavior inside asp.net mvc-5 ?
ComponentModel. DataAnnotations namespace. These attributes are used to define metadata for ASP.NET MVC and ASP.NET data controls. You can apply these attributes to the properties of the model class to display appropriate validation messages to the users.
You validation should be in Model section of MVC. As models have various fields, only models can know what combination of inputs make that model valid.
why this is not the default behavior inside asp.net mvc-5
It's not default behavior of ASP.NET MVC 5. You just need to add following css classes in Site.css file.
.field-validation-error {
color: #e80c4d;
font-weight: bold;
}
.field-validation-valid {
display: none;
}
input.input-validation-error {
border: 1px solid #e80c4d;
}
.validation-summary-errors {
color: #e80c4d;
font-weight: bold;
font-size: 1.1em;
}
.validation-summary-valid {
display: none;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With