我想用db的值设置多个下拉列表。
在这里,代码:
视图
@Html.DropDownListFor(model => model.rcf_data.lnkt_PIC, Model.Emp_list.EmployeList, new { @class = "show-tick form-control", id = "EmployeeList9", multiple = "multiple" })控制器
在控制器中,我使用MergeModel。
public ActionResult Edit(String rcf_id)
{
//List<RCFHistory> list_history_status =
MergeModel model = new MergeModel();
model.rcf_history = new List<RCFHistory>();
model.rcf_history = GetRCFHistory(rcf_id);
model.rcf_data = list_rcf.Where(r => r.lnkt_name == rcf_id).FirstOrDefault();
model.Emp_list = new ListEmployeeMaster();
model.Emp_list.EmployeList = new SelectList(GetAllEmployee(), "emp_id", "emp_name");
return View(model);
}
private IEnumerable<EmployeeNameModel> GetAllEmployee()
{
list_emp = new List<EmployeeNameModel>();
string apiUrl = "http://localhost:6161/Service1.svc";
HttpClient client = new HttpClient();
HttpResponseMessage response = client.GetAsync(apiUrl + string.Format("/GetAllEmployee")).Result;
if (response.IsSuccessStatusCode)
{
list_emp = (new JavaScriptSerializer()).Deserialize<List<EmployeeNameModel>>(response.Content.ReadAsStringAsync().Result);
}
return list_emp;
}我希望将视图中的model.rcf_data.lnkt_PIC (即List<String> )的值设置为DropDownListFor。但它总是显示出空场。
对于单个DropDownListFor,这一行适合我,它显示了我从DB获得的价值:
@Html.DropDownListFor(model => model.rcf_data.lnkt_2ndapprovalid, Model.Emp_list.EmployeList, Model.rcf_data.lnkt_2ndapprovalid, new { id = "EmployeeList2", @class = "show-tick form-control" })发布于 2021-05-10 04:12:33
从DropDownListFor到ListBoxFor的转变解决了我的问题。在我的代码中没有发生其他更改。
https://stackoverflow.com/questions/67280799
复制相似问题