I am facing issues while populating dropdownlist.
Using below code to populate IEnumerable
IEnumerable<SelectListItem> itemCollection = context.Countries.Select(item => new SelectListItem
{
Text = item.CountryName,
Value = item.CountryId
});
it gives error in Value = item.CountryId
Cannot implicitly convert type int to string.
if I changes this to Value = Convert.ToString(item.CountryId)
it give run time error
LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression.
I understand that the problem is Linq does not allow convert statement while executing. But the countrID is int in my database cannot be changed.
I know there are options to workaround this, but i need something concrete that will not make code messy?