0

鉴于此 .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>

当保存此页面和此文本框的更改时,服务器会正​​确更新“ CountryName ”和“ CountryFootnote ”。每次保存后结果窗格中的“ Model.CountryName ”和“ Model.CountryFootnote ”都是正确的。

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

表单保存后的结果


表示以之前输入的文字为准


[SAVE] 按钮编码如下:

保存按钮工作

4

2 回答 2

1

必须更新模型的“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);
}
于 2014-10-08T18:19:31.660 回答
0

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

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

于 2014-10-08T14:25:29.393 回答