网页重新加载使用Html.TexBoxFor()显示以前的输入文本而不是服务器的更新值

时间:2014-10-08 03:01:29

标签: javascript jquery razor html.textboxfor

鉴于此.cshtml摘录:

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

如果保存此页面和此文本框的更改,则服务器会同时更新&#39; CountryName &#39;和&#39; CountryFootnote &#39;正确。 &#39; Model.CountryName &#39;和&#39; Model.CountryFootnote &#39;在每次保存后,在结果窗格中点亮正确。

但是,结果还包含以前的文本输入,它仍然显示在文本框中? 见下图。

result after form save


shows that the previous input text prevails


[SAVE]按钮的编码如下:

Save Button Workings

2 个答案:

答案 0 :(得分:1)

必须更新Model的'ActionResult Edit(CustomerModel Model)'以包含此调用ModelState.Remove(“CountryName”)。
请参阅how-to-update-the-textbox-value答案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);
}

答案 1 :(得分:0)

似乎浏览器向您显示了缓存的html。

使用Ctrl + F5重新加载页面中的所有资源可以解决您的问题。