MVC dropdowlistfor 默认值无效(Selected 无效)

时间:2015-05-21 12:18:16   收藏:0   阅读:332

下面是设置无效的例子

@Html.DropDownListFor(model => model.City, ViewBag.City as IEnumerable<SelectListItem>, "==选择==", new { @class = "form-control dropdown-toggle" })

@Html.DropDownListFor(model => model.City, ViewBag.City as SelectList, "==选择==", new { @class = "form-control dropdown-toggle" })

下面是设置成功的例子
@Html.DropDownListFor(model => model.City, ViewBag.City as List<SelectListItem>, "==选择==", new { @class = "form-control dropdown-toggle" })

后端代码都是一样的,究其原因就是要把界面获取的列表转为List

 

原文:http://www.cnblogs.com/zglyzi/p/4519226.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!