Ticket Q370069
Visible to All Users

GridView - A wrong PageIndex appears in Action parameters when the grid is used in Custom Binding mode

created 12 years ago (modified 11 years ago)

[DX Support team: this thread was cloned from GridView - Сustom databinding issues]
Hello,

I'm trying the new custom binding mode on gridviews and I have several problems implementing it.
I try do display several objects which contain other objects. Here is a simplified example of what my objects looks like :

C#
public class Car { public int id; public Engine engine; public string model; public string brand; } public class Engine { public int id; public string brand; public string model; public int horsePower; }

My second problem is when I try to go to the other pages of the gridview. When my controller paging action is called, the StartDataRowIndex of the GridViewPagerState is always 0. Do you have any clue on what could cause this behavior?
Thanks.
Here is my controller code :

C#
public class CarController : Controller { [HttpGet, ActionName(CarControllerAction.Car)] public ActionResult Car() { return View(CarControllerAction.Car); } [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post), ActionName(CarControllerAction.Car_Partial)] public PartialViewResult Car_Partial() { var viewModel = GridViewExtension.GetViewModel("gvCar"); if (viewModel == null) { viewModel = new GridViewModel(); viewModel.KeyFieldName = "ID"; viewModel.Columns.Add("ID"); viewModel.Columns.Add("Model"); viewModel.Columns.Add("Brand"); viewModel.Columns.Add("Engine.ID"); viewModel.Columns.Add("Engine.Brand"); viewModel.Columns.Add("Engine.Model"); viewModel.Columns.Add("Engine.HorsePower"); } viewModel.ProcessCustomBinding( MyBindingHandlers.MyGetDataRowCount, MyBindingHandlers.MyGetData); return PartialView(CarControllerAction.Car_Partial, viewModel); } [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post), ActionName(CarControllerAction.Car_Partial_Paging)] public PartialViewResult Car_Partial_Paging(GridViewPagerState pager) { var viewModel = GridViewExtension.GetViewModel("gvCar"); viewModel.Pager.Assign(pager); // pager.PageIndex is always 0 ???!!! viewModel.ProcessCustomBinding( MyBindingHandlers.MyGetDataRowCount, MyBindingHandlers.MyGetData); return PartialView(CarControllerAction.Car_Partial, viewModel); } } public class CarControllerAction { public const string Car = "Car"; public const string Car_Partial = "Car_Partial"; public const string Car_Partial_Paging = "Car_Partial_Paging"; } public static class MyBindingHandlers { static IQueryable<Car> Model { get { return new CarDAO<Car>().GetAll_Query(); } } public static void MyGetDataRowCount(GridViewCustomBindingGetDataRowCountArgs e) { e.DataRowCount = Model.Count(); } public static void MyGetData(GridViewCustomBindingGetDataArgs e) { e.Data = Model .Skip(e.StartDataRowIndex) .Take(e.DataRowCount) .ToList(); } }

And here is my view :

C#
@model GridViewModel @Html.DevExpress().GridView( settings => { settings.Name = "gvCar"; settings.CallbackRouteValues = new { Controller = "CarController", Action = CarControllerAction.Car_Partial }; settings.CustomBindingRouteValuesCollection.Add( GridViewOperationType.Paging, new { Controller = "CarController", Action = CarControllerAction.Car_Partial_Paging } ); settings.KeyFieldName = "ID"; settings.Width = System.Web.UI.WebControls.Unit.Percentage(100); settings.Settings.ShowColumnHeaders = true; settings.Settings.ShowFilterRow = true; settings.Settings.ShowFilterRowMenu = true; settings.Settings.ShowFooter = true; settings.Settings.ShowGroupButtons = true; settings.Settings.ShowGroupedColumns = true; settings.Settings.ShowGroupPanel = true; settings.Settings.ShowHeaderFilterButton = true; settings.Settings.ShowTitlePanel = true; settings.Settings.UseFixedTableLayout = true; settings.SettingsBehavior.AllowDragDrop = true; settings.SettingsBehavior.AllowFocusedRow = true; settings.SettingsBehavior.AllowGroup = true; settings.SettingsBehavior.AllowSort = true; settings.SettingsBehavior.ColumnResizeMode = ColumnResizeMode.NextColumn; settings.SettingsBehavior.ConfirmDelete = true; settings.SettingsBehavior.EnableRowHotTrack = true; settings.SettingsPager.FirstPageButton.Visible = true; settings.SettingsPager.LastPageButton.Visible = true; settings.SettingsPager.PageSize = 50; settings.SettingsPager.PageSizeItemSettings.Visible = true; settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" }; settings.SettingsCookies.Enabled = true; settings.SettingsCookies.CookiesID = settings.Name; settings.SettingsCookies.StoreColumnsVisiblePosition = true; settings.SettingsCookies.StoreColumnsWidth = true; settings.SettingsCookies.StoreFiltering = true; settings.SettingsCookies.StoreGroupingAndSorting = true; settings.SettingsCookies.StorePaging = true; settings.SettingsBehavior.EnableCustomizationWindow = true; settings.SettingsPopup.CustomizationWindow.Height = 500; settings.SettingsPopup.CustomizationWindow.Width = 250; settings.Columns.Add(column => { column.FieldName = "ID"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Model"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Brand"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.ID"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.Brand"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.Model"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); settings.Columns.Add(column => { column.FieldName = "Engine.HorsePower"; column.ColumnType = MVCxGridViewColumnType.TextBox;}); } ).BindToCustomData(Model).GetHtml()
Comments (1)
DevExpress Support Team 12 years ago

    Hello Kévin,
    I have created a sample project according to your description but have not managed to reproduce the issue. See my project in the attachment. Would you please test it and modify to demonstrate the problem? Then send the project to us so that we can examine it on our side under the same conditions.
    One of the most probable causes of this problem is that you are using the DefaultModelBinder. The GridView in CustomBinding mode requires using the DevExpressEditorsBinder (this information is added to our answer).
    When I was testing the attached MVC Application, I faced another issue. When we change a focused row, the PageIndex is not applied. To get more information about the problem, please refer to the GridView - PageIndex is not applied if a focused row has been changed in Custom Binding mode ticket.
    Your patience is greatly appreciated.

    Answers approved by DevExpress Support

    created 12 years ago (modified 12 years ago)

    Kévin,
    One of the most probable causes of this problem is that you are using the DefaultModelBinder. The GridView in CustomBinding mode requires using the DevExpressEditorsBinder. To learn more about this, please review the Binding of Data Editors article.

      Comments (2)

        Hello,
        It works well with this solution.
        Thanks.

          Yes. Adding the following code in the "Global.asax.cs" file does the trick:
          ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.