0

I fill the model and the TempData

private const string MyTempModel = "MyTempModel";

        [HttpGet]
        public ActionResult Abm()
        {
            var modelo = DependencyContainer.Instance.Resolve<MyModel>();
            modelo.Name = "Maxi" ;
            modelo.LastName = "Dam";
            TempData[MyController.MyTempModel] = modelo;

            return View(modelo);
        }

And here I want to get the values

 [HttpGet]
            public ActionResult Save()
            {
                var model = TempData[MyController.MyTempModel] as MyModel;
                return View(model);
            }

What I'm doing wrong? I lose all the values...

Thanks

MCSI
  • 2,685
  • 22
  • 33

2 Answers2

3

TempData will be around for the life the current request and the next request only...

Alex
  • 34,121
  • 5
  • 74
  • 88
1

You will want to use session if you want the data to persist over several requests.

Check this thread for more info

Community
  • 1
  • 1
Willem D'Haeseleer
  • 18,763
  • 7
  • 60
  • 96