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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:41:49+00:00 2026-06-06T14:41:49+00:00

I have a standard form in mvc4 operation. I use jQuery.post to perform postback

  • 0

I have a standard form in mvc4 operation. I use jQuery.post to perform postback to action on server:

[HttpPost]
    public ActionResult ContactUpdate(ContactClass model)
    {
      var originalContact = contactService.Get(model.Id);

      if (ModelState.IsValid && TryUpdateModel(originalContact))
      {
        contactService.Update(originalContact);
      }

      var updatedContact = contactService.Get(model.Id);

      return PartialView("ContactView", updatedContact );
    }

This works as expected, code is here only for illustration, as my issue occurs later in request. My contact service does not have update implemented (yet), so updatedContact is actually the same one as original (when you perform update all changes are ignored and old object is returned). So when I change i.e. PostCode in webpage from 555 to 666, updatedContact.PostCode is 555. I checked its value in debugger and also in view cshtml file where @Html.EditorFor(m=>m.PostCode) is called, and everywhere it has old value (not updated). The problem is that returned html (catched from net in firebug and chrome dev tools) has:

<input class="text-box" id="PostCode" name="PostCode" type="text" value="666">

This behavior is same for all properties, and as far as I know, there is no output caching (and even if it were, it is a POST request so cache should be bypassed). When I do refresh of the page, I get “old” values.

At first, I thought it is my ajaxSuccess function which does $("#myform").replaceWith(returnedText), but after double-checking response content I’m positive that problem is in returned html. How is this possible?

This bug now creates illusion that my update is working, and if it were working, I would probably not even know about it. This is potentially dangerous behavior because some properties can have value different from the one posted to controller, and user will not be able to see it after update, so I may have to refresh the whole page to workaround.

  • 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-06T14:41:50+00:00Added an answer on June 6, 2026 at 2:41 pm

    All the Html. helpers are prefers the ModelState values over the actual model values.

    If you wan’t to return an updated model from a “postback” action you need to clear the ModelState first:

    [HttpPost]
    public ActionResult ContactUpdate(ContactClass model)
    {
      var originalContact = contactService.Get(model.Id);
    
      if (ModelState.IsValid && TryUpdateModel(originalContact))
      {
        contactService.Update(originalContact);
      }
    
      var updatedContact = contactService.Get(model.Id);
    
      this.ModelState.Clear();
      return PartialView("ContactView", updatedContact );
    }
    

    This article is a good explanation of this feature of the mvc framework.

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

Sidebar

Related Questions

I have a standard form on poll.php: <form method=POST action=createpoll.php> ..blah... </form> Is there
I have a standard HTML form on a WordPress post that the visitor will
In ASP.NET MVC, I have a main standard form that posts to an action,
I have the standard 'RequiredIf' attribute for some Conditional-Validation. My form and Model are
I have a form with most of its functionality implemented using standard TAction. I
We currently have a form with the standard multi-select functionality of here are the
I have a mobile site running with jQuery Mobile. I want to have standard
I have a standard textbox and I've got jQuery on the page. I want
I have a standard html form that uses a background image. I would like
I have a standard admin change form for an object, with the usual StackedInline

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.