lundi 2 novembre 2015

Kendo grid datasource.data calling in page load mvc 3

I have one kendo grid mvc. When click on particular menu it is getting called in view load but two times. Code is given below.

This is the controller part where i used code

First method is when particular menu clicked by user

 public ActionResult HotelUtilization()
        {
            DateTime endDate = DateTime.Now;
            var startDate = new DateTime(endDate.Year, endDate.Month, 1);
            IList<DutyTravelHotelUtilization> hotelUtilizationDetails = dutyTravelService.GetDutyTravelHotelUtilizationDetails(startDate, endDate);
            Session["HotelUtilizationDetails"] = hotelUtilizationDetails;
            return View(hotelUtilizationDetails);
        }

Second method when user selects date filter and click on search button

 public ActionResult GetHotelUtilizationDetails([DataSourceRequest] DataSourceRequest request, DateTime startDate, DateTime endDate)
        {
            List<DutyTravelHotelUtilization> hotelUtilizationDetails = dutyTravelService.GetDutyTravelHotelUtilizationDetails(startDate, endDate);
            Session["HotelUtilizationDetails"] = hotelUtilizationDetails;
            return Json(hotelUtilizationDetails.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }

and below is my grid inside view

@model IList<QR.GEMS.ServiceAgent.DutyTravelServiceRef.DutyTravelHotelUtilization>

<script type="text/javascript">
   $("#btnSearch").click(function () {
        var grid = $("#GrdHotelUtilization").data("kendoGrid");
        grid.dataSource.read();
    });
   var FilterHotelUtilization = function () {
 
        var from = $("#datepickerCheckin").val();
        var to = $("#datepickerCheckout").val();

        var FilterParameters = {
            StartDate: from,
            EndDate: to
        }
        return FilterParameters;
    }
</script>

 <div id="dvHotelUtilizationGrid">
                        @(Html.Kendo().Grid(Model)
                                            .Name("GrdHotelUtilization").HtmlAttributes(new { style = "height: 600px" })
                            .Columns(columns =>
                            {

                                columns.Bound(p => p.DutyTravelReqId).Title("Request Code").Width(100);
                                columns.Bound(p => p.StaffNumber).Title("Staff Number").Width(85);
                                columns.Bound(p => p.StaffName).Title("Staff Name").Width(200);
                                columns.Bound(p => p.CityCode).Title("City Code").Width(80);
                                columns.Bound(p => p.CityName).Title("City Name").Width(150);
                                columns.Bound(p => p.HotelCategory).Title("Hotel Category").Width(130);
                                columns.Bound(p => p.HotelName).Title("Hotel Name").Width(120);
                                columns.Bound(p => p.QurrencyQAR).Title("Currency(QAR)").Width(100);
                                columns.Bound(p => p.CheckInDate).ClientTemplate("#=kendo.format(\"{0:dd-MMM-yyyy}\",kendo.parseDate(CheckInDate))#").Title("CheckIn Date").Width(100);
                                columns.Bound(p => p.CheckOutDate).ClientTemplate("#=kendo.format(\"{0:dd-MMM-yyyy}\",kendo.parseDate(CheckOutDate))#").Title("CheckOut Date").Width(100);
                                columns.Bound(p => p.Duration).Title("Duration").Width(70);
                            })
                            .Groupable()
                            .Pageable()
                            .Sortable()
                            .Filterable()
                            .Resizable(mod => mod.Columns(true))
                                    .DataSource(dataSource => dataSource
                                        .Ajax()
                                                 .PageSize(15)
                                         .Read(read => read.Action("GetHotelUtilizationDetails", "DutyTravel").Data("FilterHotelUtilization")) //

                                        )
                                        .Events(e => e.DataBound("dataBound"))
                        )
                    </div>

So when i click on particular menu it is calling first Hotel Utilization ActionResult but after that i checked through debugger it is calling FilterHotelUtilization method inside script also. So currently two request fired here. That is completely wrong. Need help.

Aucun commentaire:

Enregistrer un commentaire