多个选择列表无效ASP MVC5

时间:2017-09-27 17:45:37

标签: asp.net-mvc multi-select

我需要为模型中的属性填充多个选择列表,并选择与值列表对应的值 代码可以解释更多

var TypesList = db.HospitalTypes.Where(T => T.Active && !T.Deleted).ToList();
List<int> PackageTypes = package.HospitalTypes.Select(ht => ht.ID).ToList();

if (langID == 1)
    ViewBag.HospitalTypesList= new MultiSelectList(TypesList.Select(T => new { T.ID, Name = T.NameEn }), "ID", "Name", PackageTypes);
else
    ViewBag.HospitalTypesList= new MultiSelectList(TypesList.Select(T => new { T.ID, T.Name }), "ID", "Name", PackageTypes);

return View(package);

查看

            <div class="form-group">
                <label class="control-label col-md-2">@Resource.HospitalType</label>
                <div class="col-md-10">
                    @Html.ListBoxFor(model => model.HospitalTypes, (IEnumerable<SelectListItem>)ViewBag.HospitalTypesList, new { @class = "form-control", @multiple = "True", @required = "True" })
                    @Html.ValidationMessageFor(model => model.HospitalTypes, "", new { @class = "text-danger" })
                </div>
            </div>

这是我在浏览器中获得的图像的链接 https://i.imgur.com/0c393t4.png 没有选择 这是一个链接显示调试时得到的内容 https://i.imgur.com/G53ITt0.png

0 个答案:

没有答案