Domanda

Following is one of the property in my MVC model.

[Display(Name = "Event ID")]
[MaxLength(8, ErrorMessage = "Event ID can be of maximum 8 characters long")]
[Required(ErrorMessage="Event ID must be entered")]
public Nullable<int> ID_EVENTO { get; set; }

I have bound the model with a View, and when I try to click "Submit" button, it gives following runtime error -

Unable to cast object of type 'System.Int32' to type 'System.Array'

While, if I remove the "MaxLength" attribute, it starts working.

What could be the issue here?

È stato utile?

Soluzione

MaxLength is used to specify the maximum length of array or string data allowed in a property.

Your ID_EVENTO is a nullable int (rather than array or string), that's why the attribute doesn't work. Sounds like you either want to remove the attribute or use a different one - Range or something?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top