在MVC中使用DropDownList接受从Controller传过来的值的方式:
控制器代码:
public ActionResult Index() { dk.bll.edu.EduBll<dk.model.edu.SetupRecord> setUpBll = new dk.bll.edu.EduBll<dk.model.edu.SetupRecord>(); List<dk.model.edu.SetupRecord> list = _setUpBll.GetMany(c => c.KeId == _upId && c.MenuCode == "jpjiaxiao").ToList(); var t = new SelectList(list.Select(m => m.s2)); ViewBag.schoolname = t; return View(); }视图代码:
<div id="cmg-dialog"> <div class="toolbar"> <a id="icon-cmgsave">保存</a><a id="icon-cmgclose">关闭</a> </div> <form class="d-dopen" id="addfrm"> <p> <span>名称:</span> @Html.DropDownList("schoolname", ViewBag.schoolname as IEnumerable<SelectListItem>, "请选择", new { @id = "cmg-campus" }) </p> <p class="hidden"> <span>版本号:</span> <input id="cmg-dnum" class="cmg-dinput" type="text" name="s2"> </p> <p class="hidden"> <span>是否有效:</span> <select id="cmg-deffect" class="cmg-dselect" type="text" name="s3"> <option value="">请选择</option> <option>有效</option> <option>无效</option> </select> </p> <p> <span></span> <input type="checkbox" name="s4"> <input type="hidden" name="id"/> </p> </form> </div>
显示结果:
此种方式下控制器通过ViewBag传值,前台通过@Html.DropDownList来进行接收
本文出自 “单脚§稻草人” 博客,请务必保留此出处http://xyh1993.blog.51cto.com/7883839/1828321
原文地址:http://xyh1993.blog.51cto.com/7883839/1828321