Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim C 161 posts 528 karma points
    Jul 05, 2020 @ 13:31
    Tim C
    0

    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

    @using Umbraco
    @using Umbraco.Core.Models
    @using Umbraco.Core.Services
    @using Umbraco.Web
    @using Umbraco.Web.WebApi
    @using Umbraco.Web.Composing
    @using Umbraco.Core.Models.PublishedContent
    @using System.Web
    
    
    @functions{
    
    private static Umbraco.Web.UmbracoHelper umbracoHelper;
    private static IPublishedContent siteDocument;
    ...
    

    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.

  • David Armitage 508 posts 2078 karma points
    Aug 04, 2020 @ 12:44
    David Armitage
    0

    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

  • Sachin Singh 1 post 71 karma points
    Aug 11, 2020 @ 05:27
    Sachin Singh
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft