TextBoxFor值发布后未更新

编程入门 行业动态 更新时间:2024-10-09 21:19:54
本文介绍了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值发布后未更新

本文发布于:2023-10-10 22:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TextBoxFor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!