首页 新闻 搜索 专区 学院

跪求大侠帮忙看下这个DropDownList编辑的问题 实在是没豆了 谢谢!

0
[已解决问题] 解决于 2012-07-26 11:06

控制器:

int etid =int.Parse(EditID);
            A_CustomerInfoModel model = new A_CustomerInfoModel();
            List<A_CustomerInfoModel> list = base.CustomerInfo.GetModelEdit(EditID) as List<A_CustomerInfoModel>;
            if (list.Count > 0)
            {
                foreach (A_CustomerInfoModel item in list)
                {
                    List<SelectListItem> items = new List<SelectListItem>();
                    items.Add(new SelectListItem { Text = "Personal", Value = "0" });
                    items.Add(new SelectListItem { Text = "Company", Value = "1"});
                    foreach (SelectListItem item_sp in items)
                    {
                        if (item_sp.Value == item.A_CutomerType)
                        {
                            var selectList = new SelectList(items, items[0].Text, items[0].Value, item.A_CutomerType);
                            ViewData["dorplist_sp"] = selectList;
                        }
                    }

                    model.A_Customer_Name = item.A_Customer_Name;
                    model.Homepage = item.Homepage;
                    model.A_province = item.A_province;
                    model.A_city = item.A_city;
                    model.A_Customer_Address = item.A_Customer_Address;
                    model.A_Customer_Post = item.A_Customer_Post;
                    model.A_Contactperson = item.A_Contactperson;
                    model.A_Contacter_Tel = item.A_Contacter_Tel;
                    model.A_IDcardNo = item.A_IDcardNo;
                    model.A_Contacter_fax = item.A_Contacter_fax;
                    model.A_Contacter_email = item.A_Contacter_email;
                }
                return View(model);
            }
            else
            {
                //没有数据
                return View();
            }          

视图代码:

@Html.DropDownList("dorplist_sp", ViewData["dorplist_sp"] as SelectList)

我改成@Html.DropDownList("dorplist_sp")也不行

页面报错提示:

DataBinding:“System.Web.Mvc.SelectListItem”不包含名为“Personal”的属性。

问题补充:

哎!!难道mvc的人那么少吗?

s_p的主页 s_p | 菜鸟二级 | 园豆:265
提问于:2012-07-25 18:16
< >
分享
最佳答案
0

 @{
                            List<object> stateListObject = new List<object>();
                            stateListObject.Add(new { value = "", text = "[Select One]" });
                                              
                                for (int r = 0; r < ViewBag.CWSTAT.Count; r++)
                                {

                                    stateListObject.Add(new { value = ViewBag.CWSTAT[r].CSTA, text = ViewBag.CWSTAT[r].CSTA });

                                    @*<option   value="@ViewBag.CWSTAT[r].CSTA"> @ViewBag.CWSTAT[r].CSTA </option>*@

                                }
                            }
                         
                         @Html.DropDownListFor(m => m.selState, new SelectList(stateListObject, "Value", "Text"), new { @class = "InputTextField", id = "txtCsta", name = "txtCsta" })

奖励园豆:5
jiangty | 菜鸟二级 |园豆:207 | 2012-07-26 11:04

谢谢你啊 朋友 我自己解决了!

s_p | 园豆:265 (菜鸟二级) | 2012-07-26 11:05
其他回答(1)
0

建议看看这篇文章:【译】详解Asp.net MVC DropDownLists

artwl | 园豆:16526 (专家六级) | 2012-07-25 18:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册