Marius Vasile

Marius Vasile

  • 600
  • 1.7k
  • 125.3k

Passing string[]parameter to OnGet in Razor Pages

Dec 26 2022 12:07 PM

I am passing multiple parameters with

public async Task<IActionResult>OnPostEvaluareAsync(string ea, string[] ecs, string ezl)
{
    return RedirectToPage("/RO/Pages/evaris/Index", new { ea, ezl, ecs });
}

and is working well, I get multiple ecs parameter when the case. The problem I have is to get data based on all those parameters at the same time

public async Task<IActionResult> OnGetAsync(string ea, string ezl, string[]ecs)
{
    if(ecs != null)
    {
        foreach(var dataGet in ecs)
        {
            EvarisListCS = await (from a in _context.EvarisCaracterSpecials.Where(s => s.OrgID == orgid && s.ECS == dataGet)
                                  join b in _context.EvarisMains on a.ECS equals b.ECS into Temp1
                                  from c in Temp1
                                  join d in _context.EvarisMasuras on c.EMID equals d.EMID into Temp2
                                  from e in Temp2
                                  select new EvarisMasuraListCS
                                  {
                                      ECS = a.ECS,
                                      OrgID = a.OrgID,
                                      CaracterSpecial = a.Denumire,
                                      Pericol = c.Categorie,
                                      FormaManifestare = c.FormaManifestare,
                                      RiscInitial = c.Risc,
                                      Clasa = e.Clasa,
                                      Masura = e.Masura,
                                      RiscFinal = e.RiscFinal
                                  }).ToListAsync();
            if(EvarisListCS.Count > 0)
            {
                HaveListCS = true;
            }
        }
    }
}

but I'm getting only one result. How do I get all the data if I have two or more parameters for ecs?

Thank you


Answers (11)