MVC动态绑定下拉框

Controller:
1//获取下拉信息表
//_vendorsAppService.GetAllObj() 是获取下拉列表结果集
2 ViewData["vendlist"] = new SelectList(_vendorsAppService.GetAllObj(), "Id", "Name", dto.VendorsId);

View:
<div class="form_group fl">
<label class="gry fl">供应商:</label>
@Html.DropDownList("sVendorsId", ViewData["vendlist"] as IEnumerable<SelectListItem>, new { @class = "btn dropdown-toggle form-control" })
</div>

或者
Controller:

  WithdrawalsApplyDto dto = new WithdrawalsApplyDto();
  IEnumerable<SelectListItem> selList2 = TxEnumHelper.EnumToListItem(typeof(WithdrawalsApplyDto.StateWithdrawalsApply), dto.State);
  ViewData["State"] = selList2;

View:
<div class="form_group fl">
<label class="gry fl">供应商:</label>
@Html.DropDownList("DDLState", ViewData["State"] as IEnumerable<SelectListItem>, new { @class = "btn dropdown-toggle form-control" })
</div>
 

  

 

posted @ 2017-11-26 17:29  EndlessLearning  阅读(266)  评论(0编辑  收藏  举报