我希望在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
',但似乎有一个同名的扩展方法。扩展方法无法动态分派。考虑将动态参数强制转换或使用非扩展方法语法调用扩展方法。
我不理解这个错误,我该检查什么?
ViewBag.MagNo
强制转换为bool?
类型吗? - Dylan Czenski