grid.mvc use filtered Result in Controller

后端 未结 1 1034
闹比i
闹比i 2021-01-07 07:10

I\'am using grid.mvc(http://gridmvc.codeplex.com/) for filtering and sorting. Does anybody know how to process the filtered result in an action controller. I\'m trying to pa

相关标签:
1条回答
  • 2021-01-07 07:48

    I finally found the way to send only filtered results to controller. The solution is to save the selection to session on the "Shared/_Grid.cshtml" page like this:

    @helper RenderGridBody()
    {
    if (!Model.ItemsToDisplay.Any())
    {
    <tr class="grid-empty-text">
        <td colspan="@Model.Columns.Count()">
            @Model.EmptyGridText
    
        </td>
    </tr>
    }
    else
    {
        Session["Items"]=Model.ItemsToDisplay;
        foreach (object item in Model.ItemsToDisplay)
        {
    <tr class="grid-row @Model.GetRowCssClasses(item)">
        @foreach (IGridColumn column in Model.Columns)
        {
            @column.CellRenderer.Render(column, column.GetCell(item))
        }
    </tr>
        }
    }
    } 
    

    When the Grid.MVC is populated with data, the selection is saved to session that can be used later in the controller when executing an action.

    In the controller, you only have to call and cast the variable into the correct type:

    public ActionResult MyController()
        {
            var SelectedRows = (List<ModelType>)Session["Items"];
    
            List<ModelType> listStats = SelectedRows;
    
            // the rest of the controller code
    }
    

    I hope that will be helpful :)

    0 讨论(0)
提交回复
热议问题