0

Given this .cshtml excerpt:

<div class="controls controls-row">  
    @Html.TextBoxFor(x => x.CountryName, new  { placeholder = "Country", @class = "input-large", customerui = "Country" })                   
    @Html.DisplayTextFor(x => x.CountryFootnote)          
</div>

When changes for this page and this textbox are saved the Server updates both 'CountryName' and 'CountryFootnote' correctly. The 'Model.CountryName' and 'Model.CountryFootnote' in the results pane after each save are spot-on correct.

However, the result also contains the previous text input which remains shown in the textbox? See image below.

result after form save


shows that the previous input text prevails


The [SAVE] button is coded as follows:

Save Button Workings

kevinwaite
  • 613
  • 1
  • 8
  • 20

2 Answers2

1

Must update the Model's 'ActionResult Edit(CustomerModel Model)' to include this call ModelState.Remove("CountryName").
See how-to-update-the-textbox-value Answer 1.

[HttpPost]
public ActionResult Edit(CustomerModel model)
{
    if (ModelState.IsValid)
    {
       ...
       ...    
       // must do this so that the 'TexBoxFor()' uses the updated Model.CountryName and not the text entered
       ModelState.Remove("CountryName");        
    }

    return PartialView("CustomerEditControl", model);
}
Community
  • 1
  • 1
kevinwaite
  • 613
  • 1
  • 8
  • 20
0

Seems that the browser displayed the cached html to you.

Using Ctrl+F5 to reload all the resources in the page should fix your problem.

albusshin
  • 3,930
  • 3
  • 29
  • 57
  • Unfortunately, Ctrl+F5 takes one back to the customer search page. I am adding another image of the workings of the [SAVE] button. Note: that the field after the 'TextBoxFor()' in question is a DisplayTextFor() of the server updated 'Model.CountryFootnote' and it is faithfully updated every time [SAVE] is clicked, using the text entered into the 'TextBoxFor()' text box. – kevinwaite Oct 08 '14 at 14:50
  • e.g., the problem is that one types "West" in the 'TextBoxFor()' text box, and then clicks on [SAVE]. They get |[West ] Western Sahara | when the expected result should be |[EH ] Western Sahara |. The typed in "West" should reflect the server converting CountryName to "EH" -- refind this customer and it does. – kevinwaite Oct 08 '14 at 14:58
  • Sorry I totally misunderstood what you asked. Unfortunately I could not diagnose the problem with the information you gave in the question, but I think the problem may lie in the Controller that handles this POST request. Have you updated the value before serving the View back to the user, or did you update the value AFTER you serve the view to the user? – albusshin Oct 08 '14 at 15:11
  • Please see the answer I just posted, tested and working nicely. – kevinwaite Oct 08 '14 at 18:24