1

So I want to know how I can get all the entries where my sessionId equals to (for example: 4).

1

    public async Task<IActionResult> Index(int? session)
    {

        var cardio = await _client.GetEntries<CardioModel>();
        
        // ContentfulCollection<CardioModel> cardioModels = new ContentfulCollection<CardioModel>();

        // foreach (var model in cardio)
        // {
        //     if(model.Session == 4){
        //         cardioModels.add(model)
        //     }
        // }

        return View(cardio);
    }

I tried this but the .add isn't a thing, I tried various ways but none of them is working and I can't find good docs about what I want. I thought probably something with .getEntriesRaw() but I don't know how to work with that.

    public async Task<IActionResult> Index(int? session)
    {
        var cardio = await _client.GetEntries<CardioModel>();
        
        // ContentfulCollection<CardioModel> cardioModels = new ContentfulCollection<CardioModel>();

        // foreach (var model in cardio)
        // {
        //     if(model.Session == 4){
        //         cardioModels.add(model)
        //     }
        // }

        return View(cardio);
    }
vimuth
  • 5,064
  • 33
  • 79
  • 116

1 Answers1

0

How about just modifying just a little bit

public async Task<IActionResult> Index(int? session)
    {
        if (session == null || session != 4) return View(null);

        var cardio = await _client.GetEntries<CardioModel>().FirstOrDefault(x => x.Session == 4);
        
        return View(cardio);
    }
Dimi Takis
  • 4,924
  • 3
  • 29
  • 41
Robban
  • 6,729
  • 2
  • 39
  • 47
  • Thanks for your help! In the meantime I got it working with a little workaround. public async Task Week1() { var cardio = await _client.GetEntries(); List cardioModels = new List(); foreach (var model in cardio){ if(model.Session == 1){ cardioModels.Add(model); } } return View(cardioModels.ToArray()); } – StrikeHacks Dec 18 '22 at 13:13