Problems with TempData message

2

I am calling a method that according to the final result shows a message or another by means of tempdata

var departamentos = Repositorios.RepositorioPersonal.getDepartamentos();
if (departamentos.Count > 0)
{
     foreach (var grabar in departamentos)
      {
         Departamento dept = new Departamento();
         dept.Descripcion = grabar.Name;
         dept.IdDepartamentoNuo = grabar.Id;
         db.Departamento.Add(dept);
      }
      db.SaveChanges();
      TempData["MsgType"] = "success";
      TempData["Msg"] = "Departamentos actualizados.";
}
else
{
  TempData["MsgType"] = "success";
  TempData["Msg"] = "No hay departamentos nuevos.";
}
return RedirectToAction("Index");

But the messages do not show them. In other methods I have this same and if it works perfectly, I do not know if there is something wrong that I do not see.

    
asked by Borja Calvo 06.10.2016 в 10:43
source

1 answer

0

Everything was fine, the problem is that calling the ActionResult ajax did not update the page and did not take the TempData.

What I have done is instead of passing TempData I have saved the messages in variables and I have passed them through JSON

    
answered by 06.10.2016 / 16:45
source