TextBoxFor值发布后未更新 [英] TextBoxFor value not updating after post

查看:69
本文介绍了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值发布后未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆