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

Multi tool use
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?





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






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.

2AQoebRYf3xg8Yq qoEGiCaRpW,3Tj A6jTj61,I5KSBLWquCaipKEOns u54M
s4 q3,Q8V,cbA B

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications