1
我认为在提交表单之前需要填写以下字段。MVC验证 - 非必填字段在提交表单前被强制填写
VIEW:
<div class="col-md-4">
@Html.EditorFor(model => model.BusinessPhone, new { htmlAttributes = new { @class = "form-control boldgray", @placeholder = "Business Phone" } })
</div>
<div class="col-md-4">
@Html.EditorFor(model => model.MobilePhone, new { htmlAttributes = new { @class = "form-control boldgray", @placeholder = "Mobile/Alternative" } })
</div>
MODEL:
[DisplayName("Home Phone")]
[Required]
public int HomePhone { get; set; }
[DisplayName("Business Phone")]
public int BusinessPhone { get; set; }
[DisplayName("Mobile Phone")]
这些字段标在我的数据库为 “允许空值”,并没有[必需]数据标注在我的模型。为什么在提交表格之前需要他们?
真棒!这很好。不幸的是,我还没有15分给你一个观点:( – dc922 2014-11-03 00:06:53
你可以标记为正确的答案 - 我想你甚至可能得到一些点? – iceburg 2014-11-03 04:40:34