I have a student consultation,
// POST: /Admin/Anuncio
[HttpPost]
public ActionResult Index(Estudante estudante)
{
if (ModelState.IsValid)
{
List<EstudantesEncontrados> list = GetEstudante(GetEstudanteProximo(estudante));
if (list != null)
{
TempData["ListaEstudantesEncontrados"] = list;
return RedirectToAction("Lista", "Busca");
}
else
{
ModelState.AddModelError("", "Erro Ao pesquisar");
}
}
// If we got this far, something failed, redisplay form
return View();
}
If I find the students redirects to the list of the students found, when I update the page in the student list it gives an error in the view because the TempData that sends the MODEL is coming null from the above action, someone could you help me?
I would like to know if there is any way when updating the browser it will get the data that was sent in the form previously.
public ActionResult Lista()
{
ViewBag.Message = "";
if (ModelState.IsValid)
{
if (TempData["ListaEstudantesEncontrados"] != null)
{
var model = TempData["ListaEstudantesEncontrados"] as List<EstudantesEncontrados>;
return View(model); ;
}
else
{
ModelState.AddModelError("", "Erro ao consultar");
return RedirectToAction("Index", "Home"});
}
}else{
return RedirectToAction("Index", "Home");
}
}