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.