Visual Studioを使用して、データベースからコントローラとビューを自動的に生成しました。データベースには、FOREIGN KEY (CategoryID) REFERENCES Categories(Id)
@ Html.DropDownList()はnullを許可する方法
を持つテーブルdbo.Itemsがあります。生成されたアイテム/作成ビューには、このアイテムが追加されます。このアイテムは、新しいアイテムを追加するときにドロップダウンリストから01カテゴリを選択します。ヌル値:
<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オプションを使用できるようにするにはどうすればよいですか?