kevinwaite
kevinwaite

Reputation: 649

Web page reload displays previous input text instead of the server's updated value, using Html.TexBoxFor()

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

Upvotes: 0

Views: 409

Answers (2)

kevinwaite
kevinwaite

Reputation: 649

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);
}

Upvotes: 1

albusshin
albusshin

Reputation: 4010

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.

Upvotes: 0

Related Questions