码迷,mamicode.com
首页 > Web开发 > 详细

MVC中为Html.DropDownListFor()添加数据项

时间:2014-10-27 17:00:14      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:for   sp   数据   html   bs   new   htm   return   nbsp   

1.控制器中取得数据,构建SelectList,利用ViewData传值到View

  

   //*****************得到所有部门名称*********//
   List<string> names = dep_m_BLL.GetAllNames();

   //*****************构建SelectList*********//
  SelectList name = new SelectList(names);

  ViewData["names"] = name;

  return View();

2.在View中添加如下编码:

  <%: Html.DropDownListFor(model => model.Inv_PP_Dep,(SelectList)ViewData["names"] ) %>

 

  

MVC中为Html.DropDownListFor()添加数据项

标签:for   sp   数据   html   bs   new   htm   return   nbsp   

原文地址:http://www.cnblogs.com/zuimei/p/4054338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!