1
我正在尋找將僱員類型設置爲經理或員工,我創建了一個枚舉屬性,但我無法獲得經理和員工值填充我的創建視圖。需要將枚舉值作爲下拉選項在我的視圖
我的模型
public string LastName { get; set; }
public enum EmployeeType {Employee, Manager }
public virtual Store Store { get; set; }
public int AssignedStore { get; set; }
我查看
<div class="form-group">
@Html.LabelFor(model => model.EmployeeType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EmployeeType, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EmployeeType, "", new { @class = "text-danger" })
</div>
</div>
您使用的是什麼版本的MVC? –
VS 2013上的MVC 5 – buckeyebmr
使用'@ Html.EnumDropDownListFor'。它僅在MVC 5中添加,但由於您使用的是MVC 5,因此您可以輕鬆前往。 –