我在数据类型为numeric(18,0)的sql server 2012数据库中得到了属性,我将如何在asp.net mvc-5应用程序中使用数据注释进行建模。
此代码给我以下错误...
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The 'PassMark' property on 'MarkScheme' could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Int32'
非常感谢
[Required(ErrorMessage = "Required Pass Mark")]
[Display(Name = "Pass Mark")]
public int PassMark { get; set; }
答案 0 :(得分:1)
使用以下属性进行验证 -
[Range(0, 999999999999999999)]
你的C#属性应该是 -
更新了编辑
public decimal PassMark { get; set; }
答案 1 :(得分:1)
我会使用[RegularExpression]。像yzi_20004但你的问题是你设置
public int PassMark { get; set; }
它应该是
public decimal PassMark { get; set; }
希望这会有所帮助
答案 2 :(得分:0)
我总是使用[RegularExpression(“^ [0-9] {0,18} $”,ErrorMessageResourceType = typeof(Messages),ErrorMessageResourceName =“ErrMsg_ID”)]