如何清除后的数据在一个ASP.NET MVC应用程序中的文本? [英] How to clear the post data for a textbox in an ASP.NET MVC application?

查看:177
本文介绍了如何清除后的数据在一个ASP.NET MVC应用程序中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,使用℃的文本渲染;%= Html.TextBox(somefield)%>从使用后的数据,例如价值如果您的网页上有验证错误,该值是从发布的数据检索和使用的价值属性。

现在,在少数情况下,我希望能够明确的是价值,换句话说,我想文本框为空,我不想MVC从发布的数据中获得的价值,并使用它的值属性,我该怎么办?如何清除后的数据?

感谢


解决方案

  ModelState.Remove(钥匙);

By default, a textbox rendered using <%= Html.TextBox("somefield")%> uses the value from the post data, e.g. if you have validation errors on your page, the value is retrieved from the posted data and used for the value attribute.

Now, in a few cases I want to be able to clear that value, in other words I want the textbox to be blank, I don't want MVC to get the value from the posted data and uses it for the value attribute, how can I do? How can I clear the post data?

Thanks

解决方案

ModelState.Remove("key");

这篇关于如何清除后的数据在一个ASP.NET MVC应用程序中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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