Was looking everywhere but couldn't find an answer. I have a webgrid which displays data from an IEnumerable. I do not want to create a view model especially for the purpose of the grid, so while creating columns, I use related properties. Like so:
grid.Column(format: @<text>
@item.User.FullName
</text>,
header: "User"),
That's for many to one relationship, and it works fine. I wanted to use similar trick with many to many like so:
grid.Column(format: @<text>
@item.Companies.FirstOrDefault().Title
</text>,
header: "Company"),
But got an error saying that
System.Collections.Generic.List<ActivityLog.Domain.Entities.Company>' does not contain a definition for 'FirstOrDefault'
Is than any other way I can source this value to use it in the webgrid?
Or should I:
opt 1) use some other presentation helper, or alternatively build an html table in foreach loop
opt 2) create view model to accommodate all properties needed for the WebGrid
Which one would be more appropriate do you think?