18
在我的视图模型我有一个属性:问题的模型绑定属性类型为int
[Required]
[MaxLength(4)]
[DisplayName("CVC")]
public int BillingCvc { get; set; }
在我看来,我用它像这样:
@Html.TextBoxFor(x => x.BillingCvc, new { size = "4", maxlength = "4" })
当我发帖的形式,我得到这个错误消息:
Unable to cast object of type 'System.Int32' to type 'System.Array'.
但是,如果我将属性更改为字符串而不是int,我不会收到错误。声明它为int允许客户端验证器检查该字段是否包含非数字。