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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:19:31+00:00 2026-05-26T02:19:31+00:00

I am having an issue changing the value of a text box in MVC

  • 0

I am having an issue changing the value of a text box in MVC 3.

I have a simple view that is returned by a controller and is typed to a custom view model. There is a text box on the view that is bound to a string property on the view model. If I populate this string on initial load then the text box value contains the value of the string. However, if I then post a form back to the same URL and change the view model string value and reload the view then the text box contains the value that was posted back, not the value that the controller supplied for the view model.

I created a simple test project to recreate the issue in the simplest way possible.

View Model:
http://www.codetunnel.com/content/images/textboxproblem/ViewModel.jpg

Controller:
http://www.codetunnel.com/content/images/textboxproblem/Controller.jpg

View:
http://www.codetunnel.com/content/images/textboxproblem/View.jpg

In the view I display the view model string value and I also bind the string property to a text box.

On initial load everything looks fine:
http://www.codetunnel.com/content/images/textboxproblem/InitialLoadTest.jpg

However, if I change the value of the text box and then press enter to POST the form things do not happen as I expected. The displayed value is the value the controller set in the action method, but the text box retains the value that was posted back:

http://www.codetunnel.com/content/images/textboxproblem/POSTTest.jpg

I’m not sure what the problem is.

  • 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-26T02:19:32+00:00Added an answer on May 26, 2026 at 2:19 am

    That is (unfortunately) the correct behavior. When using TextBoxFor or other data-bound elements, the created element is first bound against the existing ModelState, before it is bound against the model.

    The solution is to clear the ModelState in your [HttpPost] action, so that the elements in the View returned by the POST action will be bound against the model. In your POST action, add the following:

    ModelState.Clear();
    

    Personally, I think the design is incorrect, but clearing ModelState will give you the behavior you expected.

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

Sidebar

Related Questions

Having an issue with commas and values. I have a value that keeps changing
This should be simple but I'm having trouble changing some C code that uses
I am having an issue where NSDictionary is changing the values inside the <data>
Im having a weird issue here; The following .htaccess works but now (after changing
I having issue that content assistant / intellisense is working in methods such as
Hi guys I am having issue I have this query: SELECT * FROM useraccount
Just started mongo and started having issue with querying already. i have a collection
I'm having an issue with changing the attribute for an id and can't seem
New to jQuery, having an issue with dynamically changing the selector. <html> <head> <script
I am having an issue: I have a tab-bar based app. In MainWindow.xib for

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.