Visual Studio를 사용하여 데이터베이스에서 컨트롤러와 뷰를 자동으로 생성했습니다. 데이터베이스에는 dbo.Items 테이블이 있는데, FOREIGN KEY (CategoryID) REFERENCES Categories(Id)
@ Html.DropDownList() 허용 방법 NULL
생성 된 항목/생성보기에는이 항목이 있으므로 사용자는 새 항목을 추가 할 때 드롭 다운 목록에서 01 범주를 선택해야합니다. null 값 허용 :
<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 옵션은 어떻게 사용할 수 있습니까?