I'm trying to display a dropdown list of users in my view. Here is the code I'm using in my controller method:
var users = _usersRepository.Users.Select(u => new SelectListItem
{
Text = u.FirstName + " " + u.LastName,
Value = u.UserID.ToString()
}
return View(new MyViewModel { Users = users });
I get an error trying to convert UserID
to a string:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
How I create a collection of SelectListItem
from my entities?