我有一个 MVC4 项目。我正在使用带有 optgroup 的选择列表。下面的剃刀代码,
<select name="filters" id="searchable" multiple="multiple">
@foreach (var item in Model.FCategories)
{
<optgroup label="@item.FilterCategoryName">
@{
var item1 = item;
}
@foreach (var filtre in Model.Filters.Where(m => m.FilterCategoryID == item1.FilterCategoryID))
{
<option value="@filtre.FilterID">@filtre.FilterName</option>
}
</optgroup>
}
</select>
而我的模特是这样的,
[Required(ErrorMessage = "Boş Olamaz")]
public string Name { get; set; }
[Required(ErrorMessage = "Boş Olamaz")]
public string Seo { get; set; }
public IEnumerable<Filter> Filters { get; set; }
public IEnumerable<FCategory> FCategories { get; set; }
我看到带有 int? 的过滤器值。但我看不到 optgroup 值.... 我的控制器如下所示;
public ActionResult AddToCategory()
{
var fcat = _otherRepository.GetFCategories().ToList();
var filter = _otherRepository.GetFilters().ToList();
var modelim = new AdminCategoryViewModel
{
Filters = filter,
FCategories = fcat
};
return View(modelim);
}
[HttpPost]
public ActionResult AddToCategory(string seo, string name,????????? filters)
{//......}
如何在我的控制器上显示和获取 optgroup 值?