你如何验证ASP.NET MVC中的复选框?

时间:2023-01-27 12:27:06

I am wondering what methods people are using for validating check boxes in ASP.NET MVC (both client and server side).

我想知道人们使用什么方法来验证ASP.NET MVC(客户端和服务器端)中的复选框。

I am using JQuery currently for client side validation but I am curious what methods people are using, ideally with the least amount of fuss (I am looking for a new solution).

我目前正在使用JQuery进行客户端验证,但我很好奇人们正在使用什么方法,理想情况下用最少量的工作(我正在寻找新的解决方案)。

I should mention that I am currently using MVC Preview 4, and while I could upgrade to MVC Preview 5 if there is no elegant solution in MVC Preview 4, I would prefer not to at this stage just for compatibility purposes with other developers and existing solutions.

我应该提一下,我目前正在使用MVC预览版4,虽然如果在MVC预览版4中没有优雅的解决方案,我可以升级到MVC预览版5,我宁愿不在此阶段仅仅为了与其他开发人员和现有解决方案的兼容性。

Note, I have seen these related posts:

注意,我看过这些相关的帖子:

2 个解决方案

#1


1  

If you go on to the validation website and download the whole package that included the demo files, you can find the one with example of validating check boxes and radio buttons. The link is here: http://jquery.bassistance.de/validate/jquery.validate.zip

如果您继续访问验证网站并下载包含演示文件的整个软件包,您可以找到一个验证复选框和单选按钮的示例。链接在这里:http://jquery.bassistance.de/validate/jquery.validate.zip

#2


0  

I assume you simply check whether or not the name of the checkbox was posted to the server or not. Not being an ASP coder myself, I can't help, though this is how it would be done in PHP (of course, depending on how you map validations).

我假设您只是检查复选框的名称是否已发布到服务器。我自己不是ASP编码器,我无法帮助,虽然这是在PHP中完成的方式(当然,取决于你如何映射验证)。

<?php echo isset($_POST['checkbox_name']) ? 'checked' : 'not checked'; ?>

#1


1  

If you go on to the validation website and download the whole package that included the demo files, you can find the one with example of validating check boxes and radio buttons. The link is here: http://jquery.bassistance.de/validate/jquery.validate.zip

如果您继续访问验证网站并下载包含演示文件的整个软件包,您可以找到一个验证复选框和单选按钮的示例。链接在这里:http://jquery.bassistance.de/validate/jquery.validate.zip

#2


0  

I assume you simply check whether or not the name of the checkbox was posted to the server or not. Not being an ASP coder myself, I can't help, though this is how it would be done in PHP (of course, depending on how you map validations).

我假设您只是检查复选框的名称是否已发布到服务器。我自己不是ASP编码器,我无法帮助,虽然这是在PHP中完成的方式(当然,取决于你如何映射验证)。

<?php echo isset($_POST['checkbox_name']) ? 'checked' : 'not checked'; ?>