简体   繁体   中英

How to get specific entries in Contentful

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);
    }

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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM