0

I want to pass ViewBag value from one page to another. Currently, When I move to another page, the value is getting lost. Can anyone please suggest me how to retain the value after page reloads.

This piece of code is inside Home Controller and also added into its Index Page. But when I move to another page, the value is getting lost.

 ViewBag.CounryName = "USA";
MVC
  • 649
  • 7
  • 23
  • 1
    The `ViewBag` intended to pass values from controller to view only. To pass between views, use either `TempData` (recommended with `Keep()` or `Peek()`) or `Session` variables. – Tetsuya Yamamoto Jul 11 '18 at 04:48

1 Answers1

1

you can refer following post. TempData keep() vs peek(). If you still have problem then you can use Session instead of viewbag.