i am using asp.net mvc data validations with jquery Unobtrusive for validating data.
public class Register { [Required] public string Name { get; set; } [Required(ErrorMessage = "must not be empty")] public string Surname { get; set; } [EmailAddress(ErrorMessage = "please enter a valid email address")] [Required] public string Email { get; set; } }
Before form post, jquery checks the validation and lists errors on validation summary area.
My problem is;
i don't want to display errors on required attributes, i just want to paint the textarea or whatever to red - which is default behaviour with error messages.
To hide error list i used
.validation-summary-errors ul{ display: none; }
this css but it hides all of the validation errors and not just required ones. How can i achieve displaying all errors except required ones?
Note:
[Required(ErrorMessage = null)]
or
[Required(ErrorMessage = "")]
doesn't work
@Html.ValidationSummary()
in your page remove it and try.return View()
call, manually remove errors fromModelState
.