I include the set rule in the validator for my LoginModel, but when I include this RuleSet the view doesn't validate by jQuery Validate.
I use jQuery Validate Unobtrusive.
If I remove the rule the view validate correctly.
The problem is that razor doesn't include the validation rules when I include the property en the view:
@Html.TextBoxFor(m => m.Email)
@Html.ValidationMessageFor(m => m.Email)
This is the model validator with the RuleSet:
public class LoginModelValidator : AbstractValidator<LoginModel>
{
public LoginModelValidator()
{
RuleSet("login", () =>
{
RuleFor(model => model.Email)
.NotNull()
.EmailAddress();
RuleFor(model => model.Password).NotNull();
});
/*
RuleSet("forgotpass", () =>
{
RuleFor(model => model.Email)
.NotNull()
.EmailAddress();
});
*/
}
}
When send the request, in the action I include this acording the documentation in 'Validator customization' section:
[CustomizeValidator(RuleSet="login")]
for validate the rule login and it work find. The problen is in the view.
edit: validate in controller
public async Task<ActionResult> Login([CustomizeValidator(RuleSet="login")] LoginModel model)
{
if (!ModelState.IsValid)
{
...
edit: more information
I use jquery validate for validate the model. As I described before, if I not included a "ruleset" it work fine.