Adding check boxes to each row on MVCcontrib Grid

后端 未结 4 1383
说谎
说谎 2021-02-06 00:29

How can I add a checkbox to each row of a MVCcontrib grid. then when the form is posted find out which records were selected? I Am not finding much when searching for this. Tha

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 01:12

    In your view (say ReportList.cshtml) include your grid in a form and define an action for the form

    
    
    @{Html.Grid((List)ViewData["ReportList"]) .Sort((GridSortOptions)ViewData["sort"]) .Attributes(id => "grid", @class => "grid") .Columns(column => { column.For(c => Html.CheckBox("chkSelected", new { @class = "gridCheck", @value = c.ReportId })) .Named("").Encode(false) .Attributes(@class => "grid-column"); column.For(c => c.ReportName) .Named("Buyer Close Sheet Name") .SortColumnName("ReportName") .Attributes(@class => "grid-column"); }) .Render();}

    Then in your controller implement your action method

    public ActionResult SubmitReportList (string ReportListSubmit, IList chkSelected){
        // The IList chkSelected will give you a list of values which includes report ids for the selected reports and “false” for the non-selected reports. You can implement your logic accordingly. 
        return View("ReportList");
        }
    

提交回复
热议问题