I have the following LINQ code.
public List<IGrouping<Guid, ProfileImage>> GetAllUser()
{
return _profileImageRepository.QueryProfileImage()
.GroupBy(g => g.UserId)
.ToList();
}
The idea is that it will retrieve all users’ profile pictures, but if a user has more than one image, only the last image to be returned.
I’m not sure it is right, but that’s not my biggest problem.
In my controller, I have the following code.
_homeViewModel.ProfileImages = _profileImageService.GetAllUser();
ViewModel:
public List<IGrouping<Guid, ProfileImage>> ProfileImages { get; set; }
My big question is, how do I use this in my view, so that I can print the correct info.
When I look at the data in the immidiate Windows so it looks like this:
Model.ProfileImages
Count = 2
[0]: {System.Data.Objects.ELinq.InitializerMetadata.Grouping<System.Guid,Zipr.Models.ProfileImage>}
[1]: {System.Data.Objects.ELinq.InitializerMetadata.Grouping<System.Guid,Zipr.Models.ProfileImage>}
I have tried to do this:
<ul>
@foreach (var image in Model.ProfileImages)
{
<li>
<img src="@Url.Content(String.Format("~/Content/uploads/thumbs/{0}", image.ThumbPath))" alt="" />
</li>
}
</ul>
Anyone have a solution how I can access my Properties ThumbPath and more?
It doesn’t seem you’re interested in ID; so change this to return a list of
ProfileImageNow when your view loops over the images it will be actually getting a
ProfileImageObject and not an instance of anIGrouping