DropDownList 绑定的俩种写法
前台界面view 视图
@using (Html.BeginForm("Index", "CustomerInformation", FormMethod.Get)){ <p>客户名称: @Html.TextBox("SearchString") <br /> 风险级别: @Html.DropDownList("dow_riskLevel_C","") @Html.Hidden("dow_riskLevel") 入围情况: @Html.DropDownList("dow_finalistCase_C","") @Html.Hidden("dow_finalistCase") 客户策略: @Html.DropDownList("dow_customerStrategy_C","") @Html.Hidden("customerStrategy_C") 省份: @Html.DropDownList("dow_province_C","") @Html.Hidden("province_C")
<input type="submit" value="查找" id="selectBtn"/></p> }
后台Controller 数据组织用 俩种方式 组织绑定
//风险级别下拉框 数据整理 去掉重复项 var dow_riskLevel_C = from dr in db.DownSet where dr.modelName == "客户信息" && dr.modelField == "风险级别" select dr.modelvalue; dow_riskLevel_C = dow_riskLevel_C.Distinct(); ViewBag.dow_riskLevel_C = new SelectList(dow_riskLevel_C, "modelvalue");
//入围情况下拉框 数据整理 去掉重复项 var dow_finalistCase_C = from df in db.DownSet where df.modelName == "客户信息" && df.modelField == "入围情况" select df.modelvalue; dow_finalistCase_C = dow_finalistCase_C.Distinct(); List<SelectListItem> items = new List<SelectListItem>(); foreach (var item in dow_finalistCase_C) { items.Add(new SelectListItem { Text = item, Value = item }); } ViewBag.dow_finalistCase_C = items;