您好,我是使用ListBox MultiSelectList的新手,我的问题是我无法获取页面的onload值,这是我的代码
在“我的控制器”中初始化下拉值
var getddlName = (from a in nameList
where a.personId != null
&& a.personId != 0
select new SelectListItem
{
Value = a.personId.ToString(),
Text = a.personFullname
}).ToList();
ViewBag.ddlNameList = getddlName;
要获取保存的值并在加载时加载它
if (ddlPersonIds != null)
{
List<string> list1 = new List<string>();
var empIds = ddlPersonIds.Split(',');
foreach(var c in empIds){
list1.Add(c);
}
ViewBag.ddlPersonName = list1;
}
在我的视图中,这是如何将值传递给MultiselectList
我在HTML头中创建了变量容器
var ddlNameList = ViewBag.ddlNameList;
var ddlPersonName = ViewBag.ddlPersonName;
和我的MultiselectList
<div class="editor-field">
@Html.ListBox("PersonIds", new MultiSelectList(ddlNameList, "Value", "Text", ddlPersonName), new { data_placeholder = "Select Employees...", @class = "chosen input-long-75", multiple = "multiple" })
</div>
编辑:即使我在ddlPersonName
中获得了该值,也无法显示并在ddlNameList
中被选择
谢谢