我正在尝试将 selectList 插入到视图(表单)中。我想我会通过在控制器中填充列表并将其作为视图包发送到视图来实现。这是我到目前为止得到的:
var query = from p in db.ProductCategories
join pt in db.ProductCategoriesTranslations on p.ProductCategoriesId equals pt.ProductCategoriesId
where pt.ProductLanguage.Equals("se")
orderby pt.ProductCategoriesName
select new SelectListItem
{
Value = p.ProductCategoriesId.ToString(),
Text = pt.ProductCategoriesName
};
ViewBag.ProductCategoriesId = query;
return View();
然后在视图中我有:
@Html.DropDownList("ProductCategoriesId", String.Empty)
我认为这很简单明了,但是当我加载它时它会崩溃并出现以下错误:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
有什么建议么?