在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来进行接收
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。