控制器:
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的人那么少吗?
@{
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" })
谢谢你啊 朋友 我自己解决了!