0
I have grid in index page and i have another grid in Data page. 

在索引页面上的网格上,我单击单击查看记录,然后重定向到也包含网格的数据页面。我的问题是如何根据索引页面中网格中的选定记录过滤数据页面中的网格。

如您所见,在 GetAllList 方法中,我尝试使用来自索引页面上的网格的 rListID 过滤网格。

请告知我如何实现这一目标。谢谢

Index page (View)

    @(Html.Kendo().Grid<HApp.Models.SModel>()

        .Name("Grid")
        .HtmlAttributes(new { @Style = "align:center; font-size:10.5px; length:100%" })
        .Columns(columns =>
        {

            columns.Bound(p => p.RListID).Visible(false);
            columns.Bound(p => p.TListID).Visible(false);
            columns.Command(commands => commands.Edit()).Width(175);
            columns.Command(command => command.Custom("View").Click("OnshowDetails")).Width(150);


        })


        .Selectable(s => s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single))
        .Pageable()
        .Scrollable()
        .DataSource(dataSource => dataSource
            .Ajax()//bind with Ajax instead server bind
            .PageSize(10)
            .ServerOperation(true)
                .Model(model => model.Id(p => p.RListID))


            .Read(read => read.Action("GetCData", "CDetails").Type(HttpVerbs.Get))

        )
        //.Events(events => events
        //                        .Change("change"))



    )


    <script type="text/javascript">


        function OnshowDetails(e) {
           var grid = $('#Grid').data('kendoGrid');   //get a reference to the grid data 
           var record = grid.dataItem(grid.select()); //get a reference to the currently selected row
           var rListID = record.RListID;

           window.location.href = "@Url.Action("Data ", "CDetails")" + "/?rListID =" + rListID ; 




        }
    </script>


Data Page View

@(Html.Kendo().Grid<HApp.Models.SListsModel>()

    .Name("SList")
    .HtmlAttributes(new { @Style = "align:center; font-size:10.5px; length:100%" })
    .Columns(columns =>
    {
        columns.Bound(p => p.RListID).Visible(false);
        columns.Bound(p => p.CCID);



        columns.Command(commands => commands.Edit()).Width(175);      
    })


    .Pageable()
    .Selectable(s => s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single))
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()//bind with Ajax instead server bind
        .PageSize(5)
        .ServerOperation(true)
        .Model(model => model.Id(p => p.CID))

        .Read(read => read.Action("GetListData", "CDetails").Type(HttpVerbs.Get))

    )
    .Events(events => events
                            .Change("change"))



)


Controller:

    public ActionResult Index()
    {

                return View();

    }

    public ActionResult Detail()
    {

            return View();
    }


/// <summary>
        /// Bind to GetListData
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ActionResult GetListData([DataSourceRequest] DataSourceRequest request)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            return Json(GetAllList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }

         private static IEnumerable<SListsModel> GetAllList(Guid rListID)
        {


            var context = new HEntities();

            return context.SLists
                .Where(filter => filter.RListID== rListID)
                .Select(s_list => new SessionListsModel
                {

                    RListID = s_list.RListID,
                    CCID = s_list.CCID,



                });

        }



 public ActionResult GetCData([DataSourceRequest] DataSourceRequest request)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            return Json(GetAllComList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// Get all available session from Session table
        /// </summary>
        /// <returns></returns>
        private static IEnumerable<SModel> GetAllComList()
        {
            var context = new HEntities();

            return context.SM
                .Select(com_list => new SModel
                {
                    RListID = com_list.RListID,
                    PortID = com_list.PortID ,



                });

        }
4

1 回答 1

1

要设置 Grid 的初始过滤,我建议您使用 DataSource 配置器对象的Filter方法。

.DataSource(dataSource => dataSource
            .Ajax()                
            .Filter(flt=>flt.Add(c=>c.RListID).EndsWith(rListIDValuePassedFromController))
于 2012-11-14T18:33:03.133 回答