Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
阅读GridMVC在javascript中选择行按钮单击_Javascript_Asp.net Mvc_Asp.net Mvc 5_Grid.mvc - Fatal编程技术网

阅读GridMVC在javascript中选择行按钮单击

阅读GridMVC在javascript中选择行按钮单击,javascript,asp.net-mvc,asp.net-mvc-5,grid.mvc,Javascript,Asp.net Mvc,Asp.net Mvc 5,Grid.mvc,我在带有复选框的项目中使用了GridMVC。 单击按钮时,我需要读取选中的复选框所在的行。 我试图通过点击按钮从GridMVC中读取所有数据,但不起作用 我的代码 网格 @using GridMvc.Html @{ if (Model != null) { <div class="table-responsive"> @Html.Grid(Model).Columns(columns => {

我在带有复选框的项目中使用了GridMVC。 单击按钮时,我需要读取选中的复选框所在的行。 我试图通过点击按钮从GridMVC中读取所有数据,但不起作用

我的代码

网格

@using GridMvc.Html

@{
    if (Model != null)
    {
        <div class="table-responsive">
            @Html.Grid(Model).Columns(columns =>
            {
               columns.Add()
               .Encoded(false)
               .Sanitized(false)
               .SetWidth(10)
               .RenderValueAs(o => Html.CheckBox("checked", o.select));
               columns.Add(c => c.product_code).Titled(Resources.Resource.product_id);
               columns.Add(c => c.product_name).Titled(Resources.Resource.product_name);
               columns.Add(c => c.unit).Titled(Resources.Resource.unit);
            }).WithPaging(10).Sortable(true).EmptyText("No data found").Named("GridSearch")
        </div>
    }
    else
    {
        <label>No Data Found</label>
    }

}

如何在javascript中读取GRIDMVC。

您可以使用HTML元素找到行

网格

@Html.Grid(Model).Columns(columns =>
   {
       columns.Add()
       .Encoded(false)
       .Sanitized(false)
       .SetWidth(10)
       .RenderValueAs(o => new HtmlString
               (
                 "<input id='hiddenValue' type='hidden' class='check' value='" + o.Id + "'/>"+
                 "<input type='checkbox' class='check' value=" +o.select+"/>"
               ));
       columns.Add(c => c.FirstName).Titled("First Name");
       columns.Add(c => c.LastName).Titled("Last Name");
   }).WithPaging(10).Sortable(true).EmptyText("No data found").Named("GridSearch")

带有类选择器
.grid mvc
的元素在哪里?我在你的代码示例中没有找到它。您想发布所选行还是该网格内的所有行?其类名为grid div@tetsuyayayamamoto您能解释更多吗?我测试了这个代码。它可以在选中复选框的情况下正确查找当前页面的行。我正在尝试获取“First Name”的值,但没有显示给我。您可以使用的内部文本获取FirstName。查看我的javascript代码。我使用内部文本编辑了显示FirstName和LastName警报的代码。
 $('#btnok').click(function () {

        var items = $('.grid-mvc').val();
        alert(items);
    })
@Html.Grid(Model).Columns(columns =>
   {
       columns.Add()
       .Encoded(false)
       .Sanitized(false)
       .SetWidth(10)
       .RenderValueAs(o => new HtmlString
               (
                 "<input id='hiddenValue' type='hidden' class='check' value='" + o.Id + "'/>"+
                 "<input type='checkbox' class='check' value=" +o.select+"/>"
               ));
       columns.Add(c => c.FirstName).Titled("First Name");
       columns.Add(c => c.LastName).Titled("Last Name");
   }).WithPaging(10).Sortable(true).EmptyText("No data found").Named("GridSearch")
<div id="newgrid" class="col-sm-12 table-responsive" style="width:100%;height:300px;margin-top:3%;padding-left:0px;padding-right:0px;">
    @Html.Partial("ResultGrid", Model)
</div>
$('#btnok').click(function () {        
    //for find all row
    var items = $(".grid-mvc").find(".grid-table > tbody").children();

    $.each(items, function (i, row) {            
        if ($(row).find('.check').is(':checked')) {
            //get text of firstname column using inner text.
            alert($(row).children()[1].innerText);
            //get text of lastname column using inner text.
            alert($(row).children()[2].innerText);
            //using each loop get data with checked row.
            alert($(row).find('#hiddenValue').val())
        }
    })        
})