Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • TempData Vs Session in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 407
    Comment on it

    TempData

    • TempData provide communication between Controller action and it's corresponding view by transferring and maintaining data. The tempdata is retained not only for current request but also retained in case of redirection.
    • ASP.net MVC will automatically destroy the value of tempdata once subsequent request returned the desired result i.e it will live till redirected view is fully loaded. 
    • The value of TempData can be retained via keep method.

      Example

      TempData.Keep()

      TempData.Keep(“EmpName”)

    • The value of TempData is internally stored in session variable.

    •  One time messages or short lived data like validation messages, error messages etc can be stored in TempData.

    Session

    • Session is able to store data much more long time than TempData i.e it retains data until user session does not expire.
    • Once the session time out occurs the session will automatically expire. The session is valid not only for current or redirected request like TempData but also valid for all requests.
    • There is such method as keep method in TempData.
    • SessionStateItemCollection object which is exposed through the HttpContext.Session property of page are used to store session variable.
    • Session is basically used to store data whose life is long like userid or any other id which is required for entire user session.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: