如何提交选中复选框也 [英] how to submit unchecked checkbox also

查看:248
本文介绍了如何提交选中复选框也的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果未选中复选框,单击提交表单按钮不会提交任何数据。

If checkbox is not checked, clicking in form submit button does not submit any data.

一些复选框会根据用户选择的表单字段不present形式。因此,提交控制器没有可能性,以确定在形式或不被选中的复选框present。
如果数据库包含真正的此列,这个属性不更新为false。
复选框的名字是相同的数据库布尔列名。

Some checkboxes may be not present in form depending on form fields selected by user. So submit controller has no possibility to determine was unchecked checkbox present in form or not. If database contains true for this column, this property is not updated to false. Checkbox name is same as database boolean column name.

如何强制表单提交复选框这是在未选中状态或任何其他想法
在数据库设置为false值,如果复选框未被选中,但不要在数据库中更改值,如果复选框不可在形式上present?

How to to force form to submit checkboxes which are in unchecked state or any other idea to set value in database to false if checkbox is not checked but not to change value in database if checkbox is not present in form ?

的jQuery,jQueryUI的,asp.net 2使用MVC艾云

jquery, jqueryui, asp.net 2 mvc arve used

推荐答案

这是用HTML表单复选框一个共同的问题,是不是唯一的ASP.NET。

This is a common issue with checkboxes in HTML forms and isn't unique to ASP.NET.

答案是有,伴随着每一个复选框一个隐藏字段。当复选框被修改,使用客户端事件更新的隐藏字段。

The answer is to have a hidden field that accompanies each checkbox. When the checkbox is modified, use a client-side event to update the hidden field.

隐藏字段始终被提交。

不过,由于您使用ASP.NET MVC,如果你使用 HTML.CheckBoxFor 帮手,它会自动处理这个给你。

However, since you're using ASP.NET MVC, if you use the HTML.CheckBoxFor helper, it will handle this for you automatically.

这篇关于如何提交选中复选框也的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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