我的模型包含double
类型字段和string
。
[Display(Name = "Amount", ResourceType = (typeof(Resources.Work)))]
public double Amount { get; set; }
[Display(Name = "AmountInWords", ResourceType = (typeof(Resources.Work)))]
public string AmountInWords{ get; set; }
在ajax通话之后我在提交之前清除字段,即使它不是必需属性,但它始终显示Amount Field is Required
事件没有Required
属性。
Razor查看:
@Html.EditorFor(m => m.Amount, new { htmlAttributes = new { @class = "form-control", type = "number"} })
@Html.EditorFor(m => m.AmountInWords, new { htmlAttributes = new { @class = "form-control" } })
脚本
$("#Amount").val('');
$("#AmountInWords").val('');
答案 0 :(得分:1)
在模型中使用可空变量:double?
[Display(Name = "Amount", ResourceType = (typeof(Resources.Work)))]
public double? Amount { get; set; }
或:
@{ Html.EnableClientValidation(false); }
@Html.EditorFor(m => m.Amount, new { htmlAttributes = new { @class = "form-control", type = "number"} })