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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:42:40+00:00 2026-06-02T22:42:40+00:00

Ran into a very strange problem here using MVC3 and razor. The app I’m

  • 0

Ran into a very strange problem here using MVC3 and razor.

The app I’m putting together shows a series of interview questions. I have a view for a question (the content of the question comes from the viewmodel). So after I post back from one question it is possible I will be returning the same question view (but using a different viewmodel instance).

In the viewmodel I have a long property like so:

public long QuestionID { get; set; }

I was trying to use a hidden input field to store the value in the view:

@Html.HiddenFor(m => m.QuestionID)

My problem is that as I go from question to question the hidden field is not changing in the final generated html. It remains the value of the first questionID in all further questions. All the other content is changing just fine and I have a couple other hidden fields that are working fine. I have verified the correct values in the controller where the model is generated. I can set a breakpoint in the razor file and I can see the model is as it should be with the correct QuestionID. I tried using @Html.TextBoxFor as well and I have the same problem. When I manually make a hidden field like below it works fine, and this is what is really bothering me.

<input type="hidden" id="QuestionID" name="QuestionID" value="@Model.QuestionID" />

Any idea why this is happening?

  • 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-06-02T22:42:41+00:00Added an answer on June 2, 2026 at 10:42 pm

    After a form post, MVC keeps track of the posted values in ModelState. Even if you change the values of your model, the HiddenFor helpers will use the ModelState value first. This is due to the fact that binding may have failed, or binding may be a complex object and the string value in ModelState is what they actually entered.

    You can solve this by using

    ModelState.Remove("QuestionID");
    

    or, if you really just want to treat it as a completely new page,

    ModelState.Clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into very peculiar problem with BLOBs in Oracle. I'm using OracleXE 10g
I have ran into a very strange issue with Google Maps in Chrome 5.0.375.99:
I ran into a strange problem today, after renaming a couple of images in
Recently I ran into a very strange issue: touching the screen of the iPhone
Ok, so I've ran into a very strange issue, directly connected with before blocks.
I've began working with asp.net mvc very recently and I've ran into a problem.
I ran into a very weird problem today. Long story short, my function returns
Today I ran into a very difficult TDD problem. I need to interact with
I ran into a problem that is very similar to other SO question (
I recently ran into a problem caused by using fstream::eof(). I read the following

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.