If I instantiate siteDocument on one page using a function, and then navigate to another page, does siteDocument still exist or do I have to instantiate this on every page, in other words, do objects persist in App_code for the life of the session, or are they lost once navigating away from the original page?
There are multiple ways to achieve the same
1.Viewbag :- for single request from controller to view
2.Viewdata:- for single request from controller to view
3.Session:- for single request across the application
4.tempdata :- for multiple request until the data is not read in the view depending upon the method you use like
Temp.Peek() or Temp.keep()
Does data persist in App_code razor between pages?
I have some razor code in App_Code with functions that I can then call from templates/partial views eg
If I instantiate siteDocument on one page using a function, and then navigate to another page, does siteDocument still exist or do I have to instantiate this on every page, in other words, do objects persist in App_code for the life of the session, or are they lost once navigating away from the original page?
I hope this makes sense.
Yes it does if you tell the data to.
You can just use the standard .net ways of doing this.
ViewBag, TempData, Session, Cookies.
TempData seems to be the most popular. https://www.tutorialsteacher.com/mvc/tempdata-in-asp.net-mvc
Regards
David
There are multiple ways to achieve the same 1.Viewbag :- for single request from controller to view 2.Viewdata:- for single request from controller to view 3.Session:- for single request across the application 4.tempdata :- for multiple request until the data is not read in the view depending upon the method you use like Temp.Peek() or Temp.keep()
this article is useful power of Tempdata
is working on a reply...