我試圖在我的視圖中填充下拉菜單。任何幫助是極大的讚賞。謝謝。LINQ to Entities只支持投射實體數據模型原始類型?
錯誤:
Unable to cast the type 'System.Int32' to type 'System.Object'.
LINQ to Entities only supports casting Entity Data Model primitive types.
控制器:
ViewBag.category = (from c in new IntraEntities().CategoryItems
select new SelectListItem() {Text=c.Name, Value=""+c.ID }).ToList<SelectListItem>();
查看:
Category:<br />@Html.DropDownList("category", (List<SelectListItem>)ViewBag.category)
Linq to enitites不支持這些類型的轉換convert.Tostring()和convert.ToDatetime().. – 2011-12-13 21:48:28