Reputation: 11
So I want to know how I can get all the entries where my sessionId equals to (for example: 4).
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);
}
Upvotes: 1
Views: 305
Reputation: 6802
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);
}
Upvotes: 0