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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:08:01+00:00 2026-05-28T19:08:01+00:00

I’m a little confused on how to use hidden fields for persisting data in

  • 0

I’m a little confused on how to use hidden fields for persisting data in my MVC application. (I am also open to using Session if that makes sense.)

Basically, I have an application that asks a series of questions (which can arrive in different orders depending on the answers given by the user). These questions are provided as a partial view from a single controller (which calls a helper method that understands the order of how the questions should be asked). When the user answers the question, the I use Ajax to submit the current answer which, updates the sidebar with their current answers. (They can go back at any time to change an answer to a question.) All the answers to my questions are stored in a single “Answers” model object (with a property for each answer).

Based on my understanding of hidden fields, I have to provide hidden fields in every single view for every single question in order to persist that data. Is this correct?

If this is correct, would it make more sense to use a Session object? I would think it would be inefficient (and very not DRY) to have to update every view with all the model types every single time. It seems people have conflicting opinions on this and I am not educated well enough in persisting data (and not using some data source) to be sure of my decision.

  • 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-28T19:08:02+00:00Added an answer on May 28, 2026 at 7:08 pm

    If you end up with a hidden field for every field/question, realize that this will also add to the payload that you’re sending down from (the DOM itself) and sending up to (form variables) the server. While this may not be bad for a few hidden fields, I think it becomes fairly unmanageable and inefficient after a while.

    Session may be a good solution here, since you don’t have to duplicate your questions with a hidden field. The downside is that you need to make a network hop (or read from an in-memory cache) each time you send data to the server to rehydrate your session.

    Without knowing a lot about your situation, I think I’d lean more towards the session idea.

    The other thought I had would be to use a single hidden field, but keep a JSON-serialized version of your model in it and use JavaScript on the client to update it and use Json.NET on the server-side to read it and work with it. Again, that really depends on the size of the data and what you’re doing with it.

    I hope this helps. Good luck!

    UPDATE

    Based on a question in a comment, here’s how you could use JSON to hold and transmit the data…. Note: I’m more of a jQuery person, so I’m using that instead of pure JavaScript to demonstrate.

    In JavaScript, you’d have a variable to hold your object:

    var questionJson = {};
    

    As questions are answered, you’d add them to the JavaScript object literal:

    $('.question').blur(function(e){
      var questionName = $(this).attr('name');  //assume the field has an attribute name that is the question name identifier
      questionJson[questionName] = $(this).val();  //this will build up your object literal with name/value pairs of questions/answers
    });
    

    When you submit the form, assign the object literal to a hidden field in the form before you actually submit…

    $('#submitButton').click(function(e){
      e.preventDefault();
      $('#hiddenFieldOfQuestionAnswerData').val(JSON.stringify(questionJson));
      $('#myQuestionAnswerForm').submit();
    });
    

    On the server side, pull the hidden field out of your form variables and use Json.NET (or other Json deserializer) to deserialize the JSON string…

    string json = Request.Form["hiddenFieldOfQuestionAnswerData"];
    QuestionAnswerModel qaData = JsonConvert.DeserializeObject<QuestionAnswerModel>(json);
    //go do stuff....
    

    Hope this helps.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.