MVC Html.textbox/dropdown/whatever won't refresh on postback

Posted by Cynthia on Stack Overflow See other posts from Stack Overflow or by Cynthia
Published on 2010-06-17T23:00:36Z Indexed on 2010/06/18 0:03 UTC
Read the original article Hit count: 569

OK, let's start with the Html.Textbox. It is supposed to contain text read from a file. The file read is based on what the user picks from a dropdown list.

The first time it is fine. The user picks a value from the dropdown list. The controller uses that value to read some text from a file, and returns that text to the view via the view model. Everything is fine.

THen the user picks another value from the dropdown list. The controller reads a new value from a file and returns it via the view model. Debugging to the LINE BEFORE THE HTML.TEXTBOX is set in the view shows that the model contains the correct value. However, the textbox itself still shows the PREVIOUS value when the page displays!

If I switch from Html.Textbox to a plain input, type="text" html control, everything works fine. That's not so hard, but the same thing happens with my dropdown list -- I can't set the selected value in code. It always reverts to whatever was chosen last. Rendering a "select" tag with a dynamically-generated option list is a pain. I would love to be able to use Html.Dropdown.

What am I missing here?? This is such a simple thing in webforms!

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about postback