获取价值复选框使用Ajax Post在MVC中检查 [英] Get Value Checkbox Checked in MVC using Ajax Post

查看:90
本文介绍了获取价值复选框使用Ajax Post在MVC中检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Helloo ...有人可以帮帮我..



这是我的代码:

Index.cshtml

<!DOCTYPE html> 
< html>
< head>
< title> jQuery With Example< / title>
@ Scripts.Render(〜/ bundles / jquery)
< script type =text / javascript>
$(function(){

$('。chkview')。change(function(){
$(this).closest('tr')。find( '.chkitem')。prop('checked',this.checked);
});

$(。chkitem)。change(function(){
var $ tr = $(this).closest('tr'),$ items = $ tr.find('。chkitem');
$ tr.find('。chkview')。prop('checked' ,$ items.filter(':checked')。length == $ items.length);
});
});

功能保存(){

}

< / script>
< / head>
< body>
< h2>访问控制 - 主页< / h2>

< br />
@using(Html.BeginForm(Index,Home,FormMethod.Post,new {RoleID =RoleID}))
{
< input type =hidden name =RoleIDvalue =1id =RoleID/>
< table id =mytable>
< tr>
< td>查看< / td>
< td>插入< / td>
< td>更新< / td>
< td>删除< / td>
< / tr>
< tr>
< td>管理员< / td>
< td>
< input type =checkboxclass =chkview chkview-1/>
< / td>
< td>
< input type =checkboxclass =chkitem chkinsert-1/>
< / td>
< td>
< input type =checkboxclass =chkitem chkupdate-1/>
< / td>
< td>
< input type =checkboxclass =chkitem chkdelete-1/>
< / td>
< / tr>
< tr>
< td>免费用户< / td>
< td>
< input type =checkboxclass =chkview chkview-2/>
< / td>
< td>
< input type =checkboxclass =chkitem chkinsert-2/>
< / td>
< td>
< input type =checkboxclass =chkitem chkupdate-2/>
< / td>
< td>
< input type =checkboxclass =chkitem chkdelete-2/>
< / td>
< / tr>
< / table>
< br />

< button type =submitclass =buttons buttons-style-1onclick =Save()> Save< / button>
}

< / body>
< / html>





HomeController.cs

 [HttpPost] 
public ActionResult Index(string RoleID,????)
{
var _roleID = RoleID;
//我如何获得列表选中的解析值复选框???
return View();
}





i想问2个问题。

1.我如何解析价值列表选中复选框使用ajax?我想要解析复选框的类名,我检查了示例我需要列表数组,如果我检查了行管理员,{'chkinsert-1','chkupdate-2'}

2.我如何获得价值收集控制器帖子中的数组?

例子:

公共ActionResult索引(字符串RoleID,array [] collChecbox)


$ b根据用户选中的复选框输入,$ b内容为collChecbox = {'chkinsert-1','chkupdate-2'}。



有人可以帮我吗? ?

解决方案

(function(){


('。chkview')。change(function(){

(this).closest('tr')。find('。chkitem')。prop('checked',this.checked);
});


Helloo... can somebody help me..

this is my Code:
Index.cshtml

<!DOCTYPE html>
<html>
<head>
    <title>jQuery With Example</title>
    @Scripts.Render("~/bundles/jquery")
    <script type="text/javascript">
        $(function () {

            $('.chkview').change(function () {
                $(this).closest('tr').find('.chkitem').prop('checked', this.checked);
            });

            $(".chkitem").change(function () {
                var $tr = $(this).closest('tr'), $items = $tr.find('.chkitem');
                $tr.find('.chkview').prop('checked', $items.filter(':checked').length == $items.length);
            });
        });

        function Save() {
           
        }

</script>
</head>
<body>
    <h2>Access Control-Home</h2>
    
    <br />
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { RoleID="RoleID" }))
{
    <input type="hidden" name="RoleID" value="1" id="RoleID" />
    <table id="mytable">
        <tr>
            <td>View</td>
            <td>Insert</td>
            <td>Update</td>
            <td>Delete</td>
        </tr>
        <tr>
            <td>Administrator</td>
            <td>
                <input type="checkbox" class="chkview chkview-1" />
            </td>
            <td>
                <input type="checkbox" class="chkitem chkinsert-1" />
            </td>
            <td>
                <input type="checkbox" class="chkitem chkupdate-1" />
            </td>
            <td>
                <input type="checkbox" class="chkitem chkdelete-1" />
            </td>
        </tr>
        <tr>
            <td>Free User</td>
            <td>
                <input type="checkbox" class="chkview chkview-2" />
            </td>
            <td>
                <input type="checkbox" class="chkitem chkinsert-2" />
            </td>
            <td>
                <input type="checkbox" class="chkitem chkupdate-2" />
            </td>
            <td>
                <input type="checkbox" class="chkitem chkdelete-2" />
            </td>
        </tr>
    </table>
    <br />
    
        <button type="submit" class="buttons buttons-style-1" onclick="Save()">Save</button>
}
    
</body>
</html>



HomeController.cs

[HttpPost]
public ActionResult Index(string RoleID, ????)
{
  var _roleID = RoleID;
  // how i can get parsing value of list checked checkbox???
  return View();
}



i want to ask 2 question.
1. how i can parsing value of list checked checkbox using ajax? i want parsing classname of checkbox which i checked example i need list of array if i checked row administrator, { 'chkinsert-1','chkupdate-2' }
2. how i can get value collection of array in controller post?
example:
public ActionResult Index(string RoleID, array[] collChecbox)

contents of collChecbox = { 'chkinsert-1','chkupdate-2'} in accordance with the user checked of checkbox input.

can somebody help me??

解决方案

(function () {


('.chkview').change(function () {


(this).closest('tr').find('.chkitem').prop('checked', this.checked); });


这篇关于获取价值复选框使用Ajax Post在MVC中检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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