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 631367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:57:25+00:00 2026-05-13T19:57:25+00:00

After a pair programming session, an interesting question came up which I think I

  • 0

After a pair programming session, an interesting question came up which I think I know the answer for.

Question: Is there any other desired way in ASP.NET MVC to retain ‘state’ other than writing to database or a text file?

I’m going to define state here to mean that we have a collection of person objects, we create a new one, and go to another page, and expect to see the newly created person. (so no Ajax)

My thoughts are we don’t want any kung-fu ViewState or other mechanisms, this framework is about going back to a stateless web.

  • 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-13T19:57:26+00:00Added an answer on May 13, 2026 at 7:57 pm

    My thoughts are we don’t want any kung-fu ViewState or other mechanisms, this framework is about going back to a stateless web.

    The example you provided is pretty easy to do without any sort of “view state kung fu” using capabilities that are already in MVC. “User adds a person and sees that on the next screen.” Let me code up a simple PersonController that does exactly what you want:

    public ActionResult Add()
    {
        return View(new Person());
    }
    
    [HttpPost]
    public ActionResult Add(PersonViewModel myNewPersonViewModel)
    {
        //validate, user entered everything correctly
        if(!ModelState.IsValid)
            return View();
    
        //map model to my database/entity/domain object
        var myNewPerson = new Person()
        {
            FirstName = myNewPersonViewModel.FirstName,
            LastName = myNewPersonViewModel.LastName
        }
    
        // 1. maintains person state, sends the user to the next view in the chain
        // using same action
        if(MyDataLayer.Save(myNewPerson))
        {
            var persons = MyDataLayer.GetPersons();
            persons.Add(myNewPersion);
    
            return View("PersonGrid", persons); 
        }
    
        //2. pass along the unique id of person to a different action or controller
        //yes, another database call, but probably not a big deal 
        if(MyDataLayer.Save(myNewPerson))
            return RedirecToAction("PersonGrid", ...etc pass the int as route value);
    
        return View("PersonSaveError", myNewPersonViewModel);
    }
    

    Now, what I’m sensing is that you want person on yet another page after PersonSaveSuccess or something else. In that case, you probably want to use TempData[""] which is a single serving session and only saves state from one request to another or manage the traditional Session[""] yourself somehow.

    What is confusing to me is you’re probably going to the db to get all your persons anyway. If you save a person it should be in your persons collection in the next call to your GetPersons(). If you’re not using Ajax, than what state are you trying to persist?

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

Sidebar

Related Questions

I'm revising for a introduction to programming exam and I have a question which
How to avoid a pair of repetitive lines before and after invocations in sample
This morning after Windows Updates ran and rebooted a pair of web servers, I
All the simple examples of geocoding load a hard-coded long/lat pair and then, after
Ex: Like binary value 1010 then after swap pair bit position value 0101
After writing: std::pair<int, int> x; Am I guaranteed that x.first and x.second are both
After asking this question ( XAMPP Mercurial installation on Windows Apache --> HgWebDir.cgi Script
I'm trying to get a next field after matching field using awk. Is there
I need to delete a k/v pair from a dictionary in a loop. After
After @cnicutar answers me on this question , I tried to send a file-descriptor

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.