Can anyone help me to figure out how do I do this when v.ID is a integer property in my model?
ViewBag.VendorID = new SelectList(db.Vendors.Select(v => new SelectListItem
{
Value = v.ID,
Text = string.Format("{0} {1} {2}", v.Title, v.Firstname, v.Secondname)
}), "Text", "Value");
return View();
I am trying to combine several properties from my model into the text of a dropdown list. This shows a compile time error, and yet if I change it to
ViewBag.VendorID = new SelectList(db.Vendors.Select(v => new SelectListItem
{
Value = v.ID.ToString(),
Text = string.Format("{0} {1} {2}", v.Title, v.Firstname, v.Secondname)
}), "Text", "Value");
then this line from my view
@Html.DropDownList("VendorID", (SelectList)ViewBag.VendorID)
raises a run-time error:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
Any thoughts on how I can resolve this apparently simple task
Thanks all.
Jason.