For a simple validation of multiple required fields i am using a custom validator explained here
I am getting the desired behavior and validation summary message is displayed correctly, but what i am missing now is the lack of validation error css class on invalid input elements, which is added when built-in validators are used.
This is the correct behavior:
<input class="input-validation-error" name="ModelName" ... />
And this is what i get when using mentioned custom validator:
<input name="ModelName" ... />
Please note that i am referring to server side validation.
UPDATE
This is my model:
public class Register
{
[MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
[Display(Name = "Name")]
public string Name { get; set; }
[MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
[Display(Name = "User name")]
public string UserName { get; set; }
}
And this is the rendered output:
<input class="text-box single-line" data-val="true" data-val-multifield="Please provide all required information" id="Name" name="Name" type="text" value="" />
<input class="text-box single-line" data-val="true" data-val-multifield="Please provide all required information" id="UserName" name="UserName" type="text" value="" />
I am now realizing that the problem i had only occurs when i decorate my entire model class with the MultiFieldRequired attribute:
[MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
public class Register
{
...
In this case no invalid field has modified css class, while in the other scenario, when i annotate every field in the model i get the same error message multiplied by the number of invalid fields.
So, to summarize - i want to have one error message regardless of the number of invalid fields and I also want that each invalid field be marked with .input-validation-error class.