I'm creating UserValidator to validate UserViewModel using FluentValidation MVC 5
public class UserValidator : AbstractValidator<UserViewModel>
{
public UserValidator()
{
RuleFor(u => u.UserName)
.NotEmpty()
.Length(1, 50);
RuleFor(u => u.Password)
.NotEmpty()
.Length(6, 20);
// How to validate Role must be selected from dropdownlist?
}
}
UserViewModel
- UserID - int
- Username - varchar(50)
- Password - varchar(20)
- RoleID - int
How to create RuleFor
for RoleID
, that user must select the role before submit?
If using DataAnnotation
, I can simply use [Required]
attribute.