我在带有复选框的项目中有 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>
}
}
看法
<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", new List<SCM_MVC.Models.Search>()); }
</div>
<div class="form-actions" style="margin-top:2%;padding-left:2%;">
<button type="button" class="btn btn-success btn-sm" id="btnok" style="width:100px"><i class="fas fa-check"></i> OK </button>
</div>
Java 脚本
$('#btnok').click(function () {
var items = $('.grid-mvc').val();
alert(items);
})
如何在 javascript 中读取 GRIDMVC。