Html.Checkbox没有preserve其在ASP.net MVC状态 [英] Html.Checkbox does not preserve its state in ASP.net MVC

查看:94
本文介绍了Html.Checkbox没有preserve其在ASP.net MVC状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用 Html.Checkbox 扩展方法创建的复选​​框,这恼人的问题。显然,复选框的状态不会(由于表单验证错误)保存在回发的情况。在深入研究MVC code本身( System.Web.Mvc.Html.InputExtensions )我发现了'检查'属性确定通过调用 htmlHelper.EvalBoolean(名)

I have this annoying issue with the checkbox created using the Html.Checkbox extension method. Apparently the state of the checkbox is not saved in case of a postback (due to a form validation error). Delving into the MVC code itself (System.Web.Mvc.Html.InputExtensions) I found out that the 'checked' property is determined by calling htmlHelper.EvalBoolean(name).

此方法查找的ViewData本身的键(名称参数中指定)。问题是,该复选框的值实际上位于所述的ModelState。调用
htmlHelper.GetModelStateValue(名称,typeof运算(布尔))将返回预期的结果。

This method looks for the key (specified in the name argument) of the ViewData itself. The problem is that the value of the checkbox is actually located in the ModelState. Calling htmlHelper.GetModelStateValue(name, typeof(bool)) would return the expected result.

这是在复选框执行漏洞?

Is this a flaw in the checkbox implementation ?

推荐答案

这个问题被张贴在的 codePLEX ,然后将其固定/ MVC中的RTM的支持。在此期间,这是一个很好的解决方法

This issue was posted on codeplex and will be fixed/supported in the MVC RTM. In the meantime, this is a nice workaround.

这篇关于Html.Checkbox没有preserve其在ASP.net MVC状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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