I'm trying to populate a combobox in a creation view inside MVC 3. This is what i've done so far:
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();
}
However when i try to run it it gives a compilation error:
Cannot implicitly convert int to string
In this post i read that doing
Value = SqlFunctions.StringConvert((double)c.ContactId)
would fix the problem however when i try to do that i get the following error:
the name 'SqlFunctions' does not exist in the current context
What i'm i doing wrong?
Update:
doing Value = c.id.ToString()
gives the error:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.