【发布时间】:2018-12-01 17:43:40
【问题描述】:
我使用 Visual Studio 从数据库中自动生成控制器和视图。在数据库中,有一个表 dbo.Items,其中有一个FOREIGN KEY (CategoryID) REFERENCES Categories(Id)
Items/Create的生成View有这个block,强制用户在添加新Item时从下拉列表中选择01 Category,不允许空值:
<div class="form-group">
@Html.LabelFor(model => model.CategoryID, "CategoryID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CategoryID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CategoryID, "", new { @class = "text-danger" })
</div>
</div>
如何使 Null 选项可用?
【问题讨论】:
标签: c# asp.net asp.net-mvc razor