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

  • Home
  • SEARCH
  • 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 8124373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:26:29+00:00 2026-06-06T06:26:29+00:00

I have a view with a model that has several fields. When I render

  • 0

I have a view with a model that has several fields. When I render the view on the GET I have a hidden field storing a code which is empty at this point. Then I POST and on the action I add a value to this code field through the model and send the model to the view like:

return View (model);

When the view renders, the hidden field does not have the code value but the view does contain all other values entered in the first step. So now when I post on a second button the model passed to the action does not contain the hidden code value I passed to it on the first post response.

If I updated the model on the first post sent it back to the view with new values, should I not get that code stored in a hidden input in the view available and being able to post it back again to the action?

I just also realized that if I change any model field on the first post back and send the updated model to the view it will only retain values from the first POST action. Do I have a cache issue here?, how do i manage this behavior? 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-06-06T06:26:31+00:00Added an answer on June 6, 2026 at 6:26 am

    You should remove it from ModelState before changing the value in your POST action:

    [HttpPost]
    public ActionResult Foo(MyViewModel model)
    {
        // update the value of the model that was POSTed to some new value
        model.SomeProperty = "some new value";
    
        // remove POSTed value from the modelstate if you intend to modify it here
        ModelState.Remove("SomeProperty");
    
        return View(model);
    }
    

    The reason you need to do this is because Html helpers such as Html.HtextBoxFor, Html.HiddenFor, … first use the value from modelstate when binding and then the value from your model. If you don’t remove the value from ModelState then the HiddenFor helper will use the original POSTed value which is an empty string and not the value you modified in your action.

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

Sidebar

Related Questions

I have a ReactiveUI-like view model. It has several properties of different types which
I have a mvvm(model view viewmodel) silverlight application that has several views that need
I have a Backbone View that has a Collection as its Model. If the
I have taken on an MVC project that has a view that displays several
We have a model EventSession which has several subtypes via STI, including NetworkingEventSession and
I have db.Model which has several properties as described below: class Doc(db.Model): docTitle =
Imagine I have a abstract FriendEvent model which has several different concrete implementations, ie.
I have a View Model that has some serious nesting. I need to populate
I have a view model that looks like this public class ViewModelRound2 { public
I have a view model that contains a Product class type and an IEnumerable<

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.