Asp.net 如何读取EditorFor为使用jQuery生成的数组

Asp.net 如何读取EditorFor为使用jQuery生成的数组,asp.net,asp.net-mvc,asp.net-mvc-3,Asp.net,Asp.net Mvc,Asp.net Mvc 3,我对我正在使用的技术感到很困惑。我正在使用EditorFor显示值 要生成的值的代码如下所示: <tr> <td>@Html.HiddenFor(m => m.ID)@Html.CheckBoxFor(m => m.Authorized)</td> <td>@Html.DisplayFor(m => m.ID)</td>

我对我正在使用的技术感到很困惑。我正在使用EditorFor显示值

要生成的值的代码如下所示:

    <tr>
                <td>@Html.HiddenFor(m => m.ID)@Html.CheckBoxFor(m => m.Authorized)</td>
                <td>@Html.DisplayFor(m => m.ID)</td>
                <td>@Html.DisplayFor(m=>m.UserName) </td>
           </tr>
 $("input:checkbox").live('click', function () {
            if ($(this).attr('checked')) {

                var ID = $(this).parent().parent().find('#ID').val();

                $.ajax({
                    type: "POST",
                    url: '<%=Url.Action("Edit","Employee") %>',
                    data: JSON.stringify(ID),
                    contentType: "application/json; charset=utf-8",
                    dataType: "html",
                    success: function () {
                    },
                    error: function (request, status, error) {
                        alert("Error: " & request.responseText);
                    }
                });
            }            });

@Html.HiddenFor(m=>m.ID)@Html.CheckBoxFor(m=>m.Authorized)
@DisplayFor(m=>m.ID)
@DisplayFor(m=>m.UserName)
我的目标是在选中复选框后,我需要发布ID值,如下所示:

    <tr>
                <td>@Html.HiddenFor(m => m.ID)@Html.CheckBoxFor(m => m.Authorized)</td>
                <td>@Html.DisplayFor(m => m.ID)</td>
                <td>@Html.DisplayFor(m=>m.UserName) </td>
           </tr>
 $("input:checkbox").live('click', function () {
            if ($(this).attr('checked')) {

                var ID = $(this).parent().parent().find('#ID').val();

                $.ajax({
                    type: "POST",
                    url: '<%=Url.Action("Edit","Employee") %>',
                    data: JSON.stringify(ID),
                    contentType: "application/json; charset=utf-8",
                    dataType: "html",
                    success: function () {
                    },
                    error: function (request, status, error) {
                        alert("Error: " & request.responseText);
                    }
                });
            }            });
$(“输入:复选框”).live('click',函数(){
if($(this.attr('checked')){
var ID=$(this.parent().parent().find('#ID').val();
$.ajax({
类型:“POST”,
url:“”,
数据:JSON.stringify(ID),
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“html”,
成功:函数(){
},
错误:功能(请求、状态、错误){
警报(“错误:&request.responseText”);
}
});
}            });
但是,var ID=$(this.parent().parent().find('#ID').val();没有定义。如何从以下生成的HTML中读取ID值:

  <td><input id="Employee_0__ID" name="Employee[0].ID" type="hidden" value="1100" /><input id="Employee_0__Authorized" name="Employee[0].Authorized" type="checkbox" value="true" /><input name="Employee[0].Authorized" type="hidden" value="false" /></td>
<td>user </td>

使用者

我不知道你在寻找什么价值

我会这样做的

var ID = $(this).parent().parent().find('#ID').attr('value');
还是这个

var ID = $(this).parent().parent().find('#ID').attr('id');

工作?

对于指定的HTML,这应该足够了,因为隐藏元素是DOM中复选框的前一个同级元素

var ID = $(this).prev().val();

也许你可以在这里找到答案:在该复选框的td中有两个隐藏字段,你在找哪一个?