I'm a nub in MVC.I've a Model:
public class Usuarios
{
[Required(ErrorMessage = "**TxtOPID is required")]
public string TxtOpID
{
get { return this.txt_opId; }
set { this.txt_opId = value; }
}
[Required(ErrorMessage="**Password is required")]
public string TxtPassword
{
get { return this.txt_password; }
set { this.txt_password = value; }
}
[Required(ErrorMessage="**Email is required")]
[RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$",ErrorMessage="**Invalid email")]
public string TxtEmail
{
get { return this.txt_email; }
set { this.txt_email = value; }
}
}
This is DataAnnotations and works fine when i try to check if all properties are valid with ModelState.IsValid propertie.
The problem is when i dont want to check ALL properties.i.e: If i want to check only TxtOPID and TxtSenha propertie,like in a Login form,where only OPID and Password are required.
How can i exclude Email propertie validation,in a specific Action in a controller?
I tried:
public ActionResult SignIn([Bind(Exclude="TxtEmail")]Usuarios usuario)
{
[...]
}
But it doesn't work,its always INVALID cause,TxtEmail is not required for that specific form.
Any ideias?