ASP.NET MVC提交有关复选框单击窗体 [英] ASP.NET MVC submitting form on checkbox click

查看:204
本文介绍了ASP.NET MVC提交有关复选框单击窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么特别的,我应该在ASP.NET做时,我想点击一个复选框时提交表单。这是我使用的一些示例HTML ...

Is there anything special I should be doing in ASP.NET when I want to submit a form when a checkbox is clicked. This is some sample HTML I am using...

<form method="post" action="#">
                <input id="hi" class="hidden-field" type="checkbox" value="true" onclick="this.form.submit();" name="hi">hi</input>
            </form>

我的jsfiddle测试了这个,当你点击复选框,它自然张贴的形式。不知怎的,我不能得到这个工作,一个MVC PartialView内。

I tested this in JSFiddle and when you click the checkbox, it naturally posts the form. Somehow I can't get this working inside a MVC PartialView.

推荐答案

使用JavaScript / jQuery的:

Use Javascript/jQuery:

$(document).on("click", "#hi", function(){
    if ($(this).is(':checked') {
        $('form').submit();
    }
});

所有你需要的是绑定的click事件的函数,该函数,调用提交()手动。

All you need is to bind a function on the click event, and in that function, call submit() manually.

这篇关于ASP.NET MVC提交有关复选框单击窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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