Once I applied custom CSS to ValidationSummary and ValidationMessageFor it appears on the page even when there are no errors. The CSS does have an image.
How do I hide the summary and errors when there are no errors?
@Html.ValidationSummary("", new { @class = "required" })
@Html.ValidationMessageFor(m => m.UserName, null, new { @class = "required" })
.required {
background-image: url(/images/required.jpg);
background-repeat: no-repeat;
height: 33px;
width: 386px;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
color: #1eb4ec;
padding-top: 16px;
padding-left: 54px;
margin-left: 30px;
}
There are already built in css types for these:
in the default css file for MVC3 projects. These are shown appropriately based on if the
ModelStatehas any errors for thePropertyspecified or any at all forValidationSummary. If no errors are present in theModelStatethen thedisplay:none;from.field-validation-validwill hide the errors.