Я хочу создать два раскрывающихся списка, но данные поступают в один раскрывающийся список, как показано ниже:
введите описание изображения здесь
идругой пустой
я хочу, чтобы B1 и B2 были в одном раскрывающемся списке
, а имя zahra в другом раскрывающемся списке
Этот код в контроллере:
// GET: Contracts/Create
public ActionResult Create()
{
var Sections = _context.Sections.ToList();
var Customers = _context.Customers.ToList();
List<SelectListItem> list = new List<SelectListItem>();
foreach (var item in Customers)
{
list.Add(new SelectListItem { Text = item.Customer_Name, Value = item.Customer_Id.ToString() });
ViewBag.Customers = list;
}
List<SelectListItem> list1 = new List<SelectListItem>();
foreach (var item in Sections)
{
list.Add(new SelectListItem { Text = item.Section_Name, Value = item.Section_Id.ToString() });
ViewBag.Sections = list1;
}
return View();
}
И это в виде
<div class="form-group">
@Html.LabelFor(model => model.CustomerId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.CustomerId, (IEnumerable<SelectListItem>)ViewBag.Customers, "Select customers", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CustomerId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SectionsId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.SectionsId, (IEnumerable<SelectListItem>)ViewBag.Sections, "Select Sections", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.SectionsId, "", new { @class = "text-danger" })
</div>
</div>