I have the following action method:
public ActionResult SignUp(Player player)
{
if (ModelState.IsValid)
{...}
}
The problem is that ModelState.IsValid always returns true even if I have errors in my Player model. In the Player class I have decorated some of the properties with data annotations for string lenth, etc. If I invoke the TryValidateModel(player) method before I invoke the ModelState.IsValid it works fine, it returns false. Any help is appreciated.
The Player model looks like this:
public class Player
{
public int PlayerID
{
get;
set;
}
[Required(ErrorMessage = "Name is required.")]
[StringLength(10, ErrorMessage = "Name must be under 11 characters.")]
public String Name
{
get;
set;
}
[Required(ErrorMessage = "Password is required.")]
[StringLength(10, ErrorMessage = "Password must be under 11 characters.")]
public String Password
{
get;
set;
}
...
}