This should work, though I don't know if it's the best solution
Subclass Auth and attribute it with ValidatorAttribute
[Validator(typeof(CustomAuthValidator))]
public class MyAuth : Auth
{
}
Change your CustomAuthValidator to use the new MyAuth type
public class CustomAuthValidator : AbstractValidator<MyAuth>
{
public CustomAuthValidator()
{
RuleFor(x => x.UserName).NotEmpty().WithMessage("Ingresa tu nombre de usuario").WithName("Nombre de Usuario");
RuleFor(x => x.Password).NotEmpty().WithMessage("Ingresa tu contraseña").WithName("Contraseña");
}
}
Change your controller to take the new MyAuth type
[HttpPost]
public ActionResult LogOn(MyAuth model, string returnUrl)
{
//This should now work as expected
if (ModelState.IsValid)
{
//TODO: Save database and other action more
}
return View(model);
}