首页 新闻 会员 周边

mvcDropDownList编辑默认选中的问题(在线等) 路过的大侠帮帮忙!

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-07-23 09:23

视图代码:

 @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)

s_p的主页 s_p | 初学一级 | 园豆:138
提问于:2012-07-21 11:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册