最佳答案
我想在 MVC 中使用 DropDownListFor
@foreach (var item in Model)
{
@Html.DropDownListFor(modelItem => item.TitleIds, new SelectList(ViewBag.TitleNames as System.Collections.IEnumerable, "TitleId", "Title.TitleText"), "No: " + ViewBag.MagNo, new { id = "TitleIds" })
}
in Controller
public ActionResult ArticleList(int id)
{
ArticleWriter_ViewModel viewModel = new ArticleWriter_ViewModel();
Func<IQueryable<NumberTitle>, IOrderedQueryable<NumberTitle>> orderByFunc = null;
Expression<Func<NumberTitle, bool>> filterExpr = null;
if (id > 0)
{
filterExpr = p => p.MagazineId.Equals(id);
}
var wholeTitles = unitOfWork.NumberTitleRepository.Get(filterExpr, orderByFunc, "Magazine,Title").ToList();
ViewBag.MagNo = wholeTitles[0].Magazine.MagNo.ToString();
ViewBag.MagId = wholeTitles[0].Magazine.Id;
ViewBag.TitleNames = wholeTitles;
return View("../Panel/Magazine/ArticleList", "_BasicLayout", viewModel);
}
但我得到了这个错误
“
System.Web.Mvc.HtmlHelper<System.Collections.Generic.IEnumerable<Cinemavaadabiat.ViewModel.ArticleWriter_ViewModel>>
”没有名为“DropDownListFor
”的适用方法,但似乎有一个名为“DropDownListFor
”的扩展方法。不能动态调度扩展方法。考虑强制转换动态参数或在不使用扩展方法语法的情况下调用扩展方法。
我不能理解这个错误,我应该检查什么?