18
votes

In my View Model I have a property:

    [Required]
    [MaxLength(4)]
    [DisplayName("CVC")]
    public int BillingCvc { get; set; }

In my view I use it like so:

@Html.TextBoxFor(x => x.BillingCvc, new { size = "4", maxlength = "4" })

When I post the form I get this error message:

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

However, if I change the property to string instead of int, I don't get the error. Declaring it as int allows the client validator to check if the field contains non numbers.

1

1 Answers

36
votes