1

I want to send a list to this method (inside the same controller)

 [HttpGet]
    public ActionResult listaExpedientesPOrCriterio(List<Expediente> expedientes)
    {

        ExpedienteListPorCriterio vm = new ExpedienteListPorCriterio(expedientes);
        //List<Expediente> expedientes = db.Expediente.ToList();
        //SelectList Tramitees = new SelectList(expedientes, "Codigo", "FechaCreacion");
        return View(vm);
    }

Im using this inside the other method, to send the list

return RedirectToAction("listaExpedientesPOrCriterio", "expedientes");

but I receive only null. Any idea whats going on?

  • You are sending a string, not a list of "expedientes". You can try something like this: return RedirectToAction("listaExpedientesPOrCriterio", new { listOfExpedientes }); where listOfExpedientes is an existing List object. – Isma Jul 02 '18 at 20:40
  • Possible duplicate of [Can we pass model as a parameter in RedirectToAction?](https://stackoverflow.com/questions/22505674/can-we-pass-model-as-a-parameter-in-redirecttoaction) – derloopkat Jul 02 '18 at 20:44
  • I check using that, and now is not getting a null, but it send an empty list. – neoMetalero Jul 02 '18 at 21:27

1 Answers1

0

You have [HttpGet] action attribute. How you intend to send to it List<T> at all? Instead, you have to use [HttpPost] and pass data in request's body, but at this case you won't can to RedirectToAction. But you can pass your expedientes list from one action to another via TempData also preserving [HttpGet]:

[HttpGet]
public ActionResult AnotherActionName()
{
    //some code...
    TempData["expedientes"] = expedientes;
    return RedirectToAction("listaExpedientesPOrCriterio"/*, "expedientes"*/);
}

[HttpGet]
public ActionResult listaExpedientesPOrCriterio(/*List<Expediente> expedientes*/)
{
    var expedientes = (List<Expediente>)TempData["expedientes"];
    var vm = new ExpedienteListPorCriterio(expedientes);    
    return View(vm);
}
Slava Utesinov
  • 13,410
  • 2
  • 19
  • 26