我正在尝试在 MVC 3 内的创建视图中填充组合框。这是我到目前为止所做的:
public ActionResult Create()
{
var db = new ErrorReportingSystemContext();
IEnumerable<SelectListItem> items = db.Locations
.Select(c => new SelectListItem
{
Value =c.id,
Text = c.location_name
});
ViewBag.locations = items;
return View();
}
但是,当我尝试运行它时,会出现编译错误:
Cannot implicitly convert int to string
在这篇文章中,我读到这样做
Value = SqlFunctions.StringConvert((double)c.ContactId)
可以解决问题,但是当我尝试这样做时,出现以下错误:
the name 'SqlFunctions' does not exist in the current context
我在做什么错?
更新:
做Value = c.id.ToString()
给出了错误:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.