本文介绍了TextBoxFor值发布后未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的强类型视图,但发布后似乎无法更新表单上的文本框.
I have a simple strongly typed view, but I cant seem to update a textbox on my form after a post.
这是我的模特:
public class Repair { public string Number { get; set; } }在我看来,这是一个TextBox:
And in my view is a TextBox:
@Html.TextBoxFor(x => x.Number)发布到控制器后,我正在尝试更新文本框:
I'm trying to update the textbox after a post to my controller:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(Repair r) { r.Number = "New Value"; return View(r); }即使我将Number设置为新值,文本框中的文本也不会更改.我究竟做错了什么?
Even though I'm setting Number to a new value, the text in the textbox does not change. What am I doing wrong?
推荐答案在设置值之前使用ModelState.Clear()
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(Repair r) { ModelState.Clear(); //Added here r.Number = "New Value"; return View(r); }更多推荐
TextBoxFor值发布后未更新
发布评论