I am adding validation for a registration form. Right now, I have this:
<div class="row">
<div class="alert alert-danger">
@Html.ValidationMessageFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.EmailAddress)
@Html.ValidationMessageFor(model => model.Company)
@Html.ValidationMessageFor(model => model.ClearTextPassword)
</div>
</div>
The validation works fine, but I have a couple of issues:
- Right now I have an empty red box when there is no validation that I would very much like to hide. How can I check to see if any validation errors exist for the model as a whole so that I can wrap this in an
if
statement? e.g.if(model.ValidationErrors.Count > 0)
- I would also like to wrap this in a
ul
, how can I check to see if validation was triggered at the property level? e.g.if(model.FirstName.FailedValidation)
Ideally I'd like to perform both of these checks from the view. Thanks!