My CarFormat object has Name and Id property. I'm fetching all carformats which ClientId is equal to the one I passing inside method. I'm doing like this
var carFormats = this.carRepository.All()
.Where(x => x.CarFormat.Any(c => c.Car.Id == someVar.CarId))
.Select(x=>x.CarFormat).AsEnumerable();
this returns me a list of CarFormat objects.
This object has properties Name
and Id
. After I add SelectListItem CarFormats as property inside my viewmodel I tried to bind this enumerable list of resources into select list
myViewModel.CarFormats = new SelectList(carFormats, "Id", "Name");
but I'm getting databinding exception DataBinding: `
'System.Collections.ObjectModel.ReadOnlyCollection1[[xxxxx, xxxxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not contain a property with the name 'Name'.
When I projection to use only first item from the list everything works, except I need this for all objects not just first
myViewModel.CarFormats = new SelectList(carFormats.First(), "Id", "Name");