ASP.NETCore中TelerikGrid复选框按钮点击迭代的解决方法。
创始人
2024-09-18 16:30:18
0
  1. 在Telerik Grid中加入复选框列。
    
    
        
    

    
        
    
  1. 为Telerik Grid的复选框按钮迭代绑定事件。
    // Step 2: Bind iteration event on button click
    $(document).ready(function () {
        $('#iterate').click(function () {
            // Get all checkboxes and filter selected ones
            var checkedIds = $('input[name="selectedIds"]:checked').map(function () {
                return $(this).val();
            }).get();

            // Do something with the selected checkboxes
            console.log(checkedIds);
        });

        // Select all checkboxes on header checkbox click
        $('#checkAll').click(function () {
            $('input[name="selectedIds"]').prop('checked', this.checked);
        });
    });
  1. 在Controller的POST方法中处理所选记录。
    // POST: Home/Index
    [HttpPost]
    public IActionResult Index(int[] selectedIds)
    {
        // Do something with selected Ids
        return PartialView("_Grid", GetData());
    }
  1. 完整的ASP.NET Core视图代码。
    @model IEnumerable

    

    

Demo

@foreach (var item in Model) { }
Name Age
@item.Name @item.Age