我正在研究 MVC4,DropdownList 没有绑定 SelectedValue。请在下面找到我的代码,我不明白哪里出错了。
我见过 SelectList ,它有 SelectedValue 但没有在 View DropdownList 中绑定它
控制器代码
public ActionResult Edit(int id)
{
Employee model = _unitOfWork.EmployeeRepository.Find(id);
ViewBag.OfficeSiteId = new SelectList(_unitOfWork.OfficeSiteRepository.Get(), "Id", "Name", model.OfficeSiteId);
return View("Edit", model);
}
看法
<div class="control-group">
@Html.LabelFor(model => model.OfficeSiteId, new {@class = "control-label"})
<div class="controls">
@Html.DropDownList("OfficeSiteId", ViewBag.OfficeSiteId as SelectList, new {@class = "chzn-select"})
@Html.ValidationMessageFor(model => model.OfficeSiteId, null, new {@class = "help-inline"})
</div>
</div>