asp.net mvc的复选框不一致 [英] asp.net mvc checkbox inconsistency

查看:141
本文介绍了asp.net mvc的复选框不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是ASP.NET MVC的形式,像这样在一个复选框:

I'm using an checkbox on an ASP.NET MVC form like so:

<%=Html.CheckBox("AgreeToRules", Model.AgreeToRules)%>

在模型上AgreeToRules属性是一个布尔值。在测试过程中,这一切都工作得很好。但是,现在我们已经住了这个程序,我看到与下列消息相对较少,但显著一些误区:

The AgreeToRules property on the model is a boolean value. During testing, this all worked fine. However, now that we've gone live with this app, I'm seeing a relatively small but significant number of errors with the following messaging:

System.Web.HttpUnhandledException:
  类型的异常
  System.Web.HttpUnhandledException
  被抛出。 --->
  System.InvalidOperationException:该
  从类型参数的转换
  'System.String'输入
  'System.Boolean'失败。见内
  例外的详细信息。 --->
  System.FormatException:Y是不是一个
  布尔有效值。 --->
  System.FormatException:字符串的不
  识别为有效的布尔值。

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.Boolean' failed. See the inner exception for more information. ---> System.FormatException: Y is not a valid value for Boolean. ---> System.FormatException: String was not recognized as a valid Boolean.

这时候出现的视图引擎尝试后后呈现的形式出现,而从ValueProvider返回的复选框的值如下:

This appears to happen when the view engine tries to render the form after a post, and the value of the checkbox that is returned from the ValueProvider looks like:

Y,假

N,虚假

这是在原来的形式呈现的HTML如下:

The html that is rendered in the original form looks like:

<input id="AgreeToRules" name="AgreeToRules" type="checkbox" value="true" />
<input name="AgreeToRules" type="hidden" value="false" />

在测试过程中,我希望(和显示)的公布值如下:

During testing, I expected (and showed) the posted value to look like:

true和false

true,false

如果检查或

如果不进行检查。那么,是N和Y是从哪里来的?

if not checked. So where is the N and Y coming from?

我添加的用户代理从错误处理程序返回的信息列表,并出现(到目前为止),所有的错误都是在Windows XP中存在的与FF 3.0.10,而这正是我与测试的在测试过程中不存在的问题。

I added user agent to the list of information returned from the error handler and it appears (so far) that all of the errors are occuring under windows XP with FF 3.0.10, but that's exactly what I have tested with and the problem did not exist during testing.

有什么想法?

推荐答案

好吧,我发现了这个问题,我想我会在这里发布的情况下,别人遇到它。某些形式的填料将通过我所使用的名称检测等领域,并尝试通过设置到任何用户有pviously用于类似命名域$ P $值填补他们自动。起昨天深夜,我也收到退订和订阅作为一个名为选择启用。

Well I found the problem, and thought I'd post it here in case others encounter it. Certain form fillers will detect the fields using the names I've used and try to "fill them" automatically by setting the value to whatever the user has previously used for similarly named fields. Starting late last night, I'm also receiving "UNSUBSCRIBED" and "SUBSCRIBED" as values for a checkbox named "OptIn".

因此​​,形式填料复选框的值的变化的东西,并且用户检查框,从而导致意想不到的值被发送到服务器。

So, the form filler changes the value of the checkbox to something and the user checks the box, resulting in the unexpected value being transmitted to the server.

在这个处理将是AP preciated任何想法。

Any thoughts on dealing with this would be appreciated.

这篇关于asp.net mvc的复选框不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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