我想在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" })
}
在控制器中
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
”的方法,但似乎具有该名称的扩展方法。扩展方法不能动态调度。考虑强制转换动态参数或在不使用扩展方法语法的情况下调用扩展方法。
我无法理解该错误,应该怎么检查?