Currently the [Required] attribute can be used on properties but not on the type itself or on the parameter. So when sending a request with empty body to the POST action below, the ModelState.IsValid would return true even though everything is missing. Right now we don't have good ways of specifying a required body parameter.
public POST(LoginModel login)
{
if (ModelState.IsValid)
{
// do something with the login parameter
}
}
public class LoginModel
{
[Required]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
}
Comments: I can't seem to get any validation using System.ComponentModel.DataAnnotations to works. In fact, I can't get ModelState.IsValid to ever be false even if the object I construct is complete garbage.