Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1094579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:59:29+00:00 2026-05-16T23:59:29+00:00

I want to maintain model state between method calls on the controller. Is that

  • 0

I want to maintain model state between method calls on the controller.
Is that possible?

A controller is created at the call of some of its methods and destroyed when the called method finishes its execution?

If not… how can I maintain the state between method calls?
If that is possible… how has it to be written?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:59:30+00:00Added an answer on May 16, 2026 at 11:59 pm

    Let’s keep this simple! 🙂

    You asked following questions:

    I want to maintain model state between method calls on the controller.

    Is that possible?

    Answer: yes, it is

    A controller is created at the call of some of its methods and destroyed when the called method finishes its execution?

    Answer: yes, it doesn’t persist any state – it just returns the result generated by the action

    If not… how can I maintain the state between method calls? If that is possible… how has it to be written?

    Answer:

    We had the same issue in our current business application using ASP.NET MVC2 and came up with following solutions:

    Solution(s):

    1st he Proof-Of-Concept for this application contained some special functionality using the global Session. (Note that the session is saved on the webserver)

    Saving and reading from session in ASP.NET MVC:

    public Action SaveIntoSession()
    {
      ...
      Session["SessionData"] = "Something to be stored in session";
      ...
    }
    
    public action ReadFromSession()
    {
      ...
      // UNBOXING is required when you're using the session as ASP.NET doesn't know what is stored into the session
      string sessionData = (string)Session["SessionData"]; 
     ...
    }
    

    2nd There’s another concept of saving the required information for each request into a Session Table into your database. (But I won’t go too deep into that.. check this article for more info – although it’s php, you can get your head around the concept pretty easily)

    3rd Would be to use the TempDataDictionary as mentioned by Charlino. The problem with this is, that it only persists the state from one call to the another. All data that is stored will be deleted by the next request. (TempData is mostly used to display errors to the user..)

    public Action SaveIntoTempData()
    {
      ...
      TempData["TempData"] = "Something to be stored ONE request ONLY";
      ...
    }
    
    public Action ReadFromTempData()
    {
       ...
       string tempData = (string)TempData["TempData"];
    }
    

    4th You could also use the ViewDataDictionary. It is not recommended to be used with sensitive data. (check this thread for more info)

    public Action SaveIntoViewData()
    {
      ...
      TempData["ViewData"] = "Something to be stored into the page";
      ...
    }
    
    public Action ReadFromViewData()
    {
       ...
       string viewData = (string)ViewData["ViewData"];
    }
    

    At the end of the day. It is up to you and your team what best matches requirements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a model that has SOME attributes that are not stored
We have a data model that has some requirements. I would like to find
I need to convert between these two classes, and want to maintain DRY but
Is this possible!!?!?!?!? I'm trying to make a set of classes that model a
I have a page in which I want to maintain the value of object
I want to create and maintain a relatively simple relational database in my java
I want to have one Drupal copy to maintain, but a lot of sites
I want my window to always maintain a certain ratio of let's say 1.33333333.
I want zip up a folder structured like so: temp/folder1/file1 temp/folder2/file2 temp/file3 and maintain
Basically I want to use a dynamic data website to maintain data in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.