Access to the list items of IDictionary in RazorPage

77 Views Asked by At

I need to list all ceremonies incase of my searchModel parameters are empty. So When the page loaded, we should have a list of multimedia albums of ceremonies. The following method doing generate this list. but I need to show items of my MultimediaViewList in RazorPage one by one. So I should access to the following items and its values in HTML part of my razor page Id,Title,CeremonyId,Ceremony,FileAddress How can I do that?

public Dictionary<string, List<MultimediaViewModel>> Search(MultimediaSearchModel searchModel)
{
    var query = _hContext.Multimedias.Include(x => x.Ceremony).Select(g => new MultimediaViewModel
    {
        Id = g.Id,
        Title = g.Title,
        CeremonyId = g.CeremonyId,
        Ceremony = g.Ceremony.Title,
        FileAddress = g.FileAddress
    }).GroupBy(g => g.CeremonyId).ToList();
    return query.ToDictionary(k => k.Key, v => v.ToList());
}

this is My View Model:

public class MultimediaViewModel
    {
        public long Id { get; set; }
        public string Title { get;  set; }
        public string FileAddress { get;  set; }
        public long CeremonyId { get;  set; }
        public string Ceremony { get; set; }
    }
1

There are 1 best solutions below

4
On

If I understood you correctly, I think the return type of your method should be a List of MultimediaViewModel, and then return query.SelectMany(x=> x).Distinct().ToList() Also, preferablly you should assign the return value of this method to a property called MultimediaViewList to use it in your razor page.