Entity Framework : send list between methods in the same controller not working

Multi tool use
Entity Framework : send list between methods in the same controller not working
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?
Possible duplicate of Can we pass model as a parameter in RedirectToAction?
– derloopkat
Jul 2 at 20:44
I check using that, and now is not getting a null, but it send an empty list.
– neoMetalero
Jul 2 at 21:27
1 Answer
1
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]
List<T>
[HttpPost]
RedirectToAction
expedientes
TempData
[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);
}
I will try to use this, Tks. I will let you know if it works.
– neoMetalero
Jul 4 at 18:27
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
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<Expediente> object.
– Isma
Jul 2 at 20:40