MVC - 如何改变在后一个文本框的值? [英] MVC - How to change the value of a textbox in a post?
问题描述
在提交我的网页的按钮,还有一个就是验证一个文本框,如果它是无效的,我用显示错误消息 ModelState.AddModelError
方法。而我需要更换这个文本框的值和错误信息返回给用户显示页面。
After a user clicks the submit button of my page, there is a textbox that is validated, and if it's invalid, I show an error message using the ModelState.AddModelError
method. And I need to replace the value of this textbox and show the page with the error messages back to the user.
问题是,我不能改变文本框的值,我试图做计算机[文本框] =新价值;
,但它被忽略......
The problem is that I can't change the value of the textbox, I'm trying to do ViewData["textbox"] = "new value";
but it is ignored...
我怎样才能做到这一点?
How can I do this?
感谢
推荐答案
您可以使用ModelState.Remove(nameOfProperty),如:
You can use ModelState.Remove(nameOfProperty) like:
ModelState.Remove("CustomerId");
model.CustomerId = 123;
return View(model);
这会工作。
这篇关于MVC - 如何改变在后一个文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!