I have a viewmodel such that, on validation, I want to compare multiple fields. I have a custom attribute that takes the viewmodel and performs the required validation. I am decorating the viewmodel class with the custom attribute [ValidateThisForm]
[AttributeUsage(AttributeTargets.Class)]
public class ValidateThisForm : ValidationAttribute
{
public override bool IsValid(object value)
{
ViewModel _viewModel = value as ViewModel;
if (_viewModel.TestOne == false && _viewModel.TestTwo == false)
{
ErrorMessage = "Form Incomplete: Please correct";
return false;
}
else
{
return true;
}
}
}
The problem is, I want to perform several "class level" validations. As a result, in my view, I can only display these errors in one place on the form:
<td class = "field-validation-error">@Html.ValidationMessageFor(viewmodel => viewmodel)</td>
Is there a way that I can have multiple "class level" errors being displayed in different locations on the form?