鉴于此 .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”。每次保存后结果 Pane 中的“Model.CountryName”和“Model.CountryFootnote”都是正确的。
但是,结果还包含先前输入的文本,该文本仍然显示在文本框中? 参见下图。
<小时/>
<小时/>
[SAVE]按钮的编码如下:
最佳答案
必须更新模型的“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);
}
关于javascript - 使用 Html.TexBoxFor() 网页重新加载显示以前的输入文本而不是服务器的更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26248564/