I am having problems to implement the asp.net mvc 5 annotations. When designing my model, I put the [StringLength]
annotation to validate that the user enters a minimum and maximum number of digits. It works well, but at the moment of making the post, I never get to the controller and when I review the response, a conversion error appears. The following is the exception.
Unable to convert an object of type 'System.Int32' to type 'System.String'
My model:
public class LoginViewModel
{
[Required]
[StringLength(8, MinimumLength = 7, ErrorMessage = "mi error")]
[Display(Name = "Rut")]
public int UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Multiclave")]
public int Password { get; set; }
}
Try with MaxValue[]
but I got the same problem. With another type of error, but based on the data conversion.
Could someone help me please?