I have a list of objects of type quote that I'm passing to a view and showing in a grid. There are a number of drop down lists above the grid for filtering. I want to populate the dropdown
lists with a distinct list of valid options based on the data for the grid. The one I'm looking at is 'Created By'.
public IEnumerable<SelectListItem> GetCreatedBy(IEnumerable<Quote> quotes)
{
var x = quotes.GroupBy(q => new {
ListValue = q.CreatedBy.samAccountName,
ListText = q.CreatedBy.DisplayName})
.Select(group => new SelectListItem {
Value = group.ListValue,
Text = group.ListText });
return x;
}
The error I'm getting is:
'IGrouping<, Quote>' does not contain a definition for 'ListValue' and no extension method 'ListValue' accepting a first argument of type 'IGrouping<, Quote>' could be found (are you missing a using directive or an assembly reference?)
The 'Quote' has a 'User' object as the 'Created By' I want a DropDownList populated with the distinct Users samAccountName and DisplayName without having to re-query to get this list.
I've tried .Distinct()
and different versions of the code above with .GroupBy()
.
I'm new to MVC
and really new to lambda expressions. Any help would be very much appreciated.