视图代码:
@SelectList lst=ViewData["A_MuData_type"]as SelectList; foreach(var item in lst) { if(lst.Value==@dr["MDTCompany"]) { lst=new SelectList(ViewData["proplist"]as SelectList,"EqManufacturers", "EqManufacturers", item.Value); break; } } @Html.DropDownList("un.categories", lst)
这个视图代码有错误啊 大侠们 帮忙看下!
控制器代码:
public ActionResult AddVehicle(string ObjectID) { string ObID = Request["ObjectID"].Trim(); if (!string.IsNullOrEmpty(ObID)) { List<A_MuData> categories = base.CustomerInfo.GetModel() as List<A_MuData>; ViewData["A_MuData_type"] = new SelectList(categories, "EqManufacturers", "EqManufacturers"); un.dt = base.CustomerInfo.SelectModel(ObID); return View(un); } else { return View(); } }
还有为什么我的控制器保存的时候 获取不到这个dorplist的值呢?
代码:
[HttpPost] public ActionResult InsertVehicle(string Action, FormCollection fc) { switch (Action) { case "OK": { break; } case "保存1": { break; } case "OK(Third)": { un.model.ObjectID =Convert.ToInt16(fc["ObjectID"]); un.model.Pversion = fc["un.categories"]; un.model.EqManufacturers = fc["Eqtypes"]; un.model.Eqtypes = fc["Pversion"]; bool flg= base.CustomerInfo.InsertModel(un.model); break; }
其他的获取没问题
我自己解决了 谢谢!
代码:
List<A_MuData> categories = base.CustomerInfo.GetModel() as List<A_MuData>;//加载所以的droplist列表 List<A_MuData> DefaultSelect = base.CustomerInfo.GetModel(ObID) as List<A_MuData>;//查询当前数据默认的值 var selectList = new SelectList(categories, "EqManufacturers", "EqManufacturers", DefaultSelect[0]);//第4个参数就是代表默认选中的意思! ViewData["A_MuData_type"] = selectList; un.dt = base.CustomerInfo.SelectModel(ObID); return View(un);
视图:
@Html.DropDownList("un.categories", ViewData["A_MuData_type"] as SelectList)