mvc 二级联动下拉列表出现的问题????
--------------------编程问答-------------------- 你的接受模型应该是个实体,而不应该是列表集合示例如下
DropDownListFor常用的是两个参数的重载,第一参数是生成的select的名称,第二个参数是数据,用于将绑定数据源至DropDownListFor
Modle:
public class SettingsViewModel
{
Repository rp =new Repository();
public string ListName { get; set; }
public IEnumerable<SelectListItem> GetSelectList()
{
var selectList = rp.GetArea().Select(a => new SelectListItem {
Text=a.AreaName,
Value=a.AreaId.ToString()
});
return selectList;
}
}
Controller:
public ActionResult Index()
{
return View(new SettingsViewModel());
}
View:
@model Mvc3Applicationtest2.Models.SettingsViewModel
@Html.DropDownListFor(m=>m.ListName,Model.GetSelectList(),"请选择")
--------------------编程问答-------------------- 好的,我考虑一下你的方法。还有我刚才按错了,丢了个板砖,对对对不起。。。。
补充:.NET技术 , ASP.NET