This is a migrated thread and some comments may be shown as answers.

GridCommand is always empty with CustomBinding

2 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 06 May 2010, 12:30 AM
There must be something simple that I am doing wrong. I am trying to get a simple paging scenario working with CustomBinding before I try anything too complicated. Here is my view:

                <%
                   Html.Telerik().Grid<AuditSummary>()
                       .Name("AuditGrid")
                       .BindTo(Model.AuditSummaryQuery)
                       .Columns(columns =>
                                    {
                                        columns.Bound(a => a.Id);
                                        columns.Bound(a => a.UserNameFirstLast).Title("User");
                                        columns.Bound(a => a.Action);
                                        columns.Bound(a => a.Event);
                                        columns.Bound(a => a.IPAddress);
                                        columns.Bound(a => a.DateTime);
                                    })
                       .Pageable(settings => settings.Total(Model.RecordCount))
                       .EnableCustomBinding(true)
                       .Sortable()
                       .Render();
                %>

And here is my Controller:

        [Authorize, GridAction(EnableCustomBinding = true)]
        public ActionResult Index(GridCommand command)
        {
            if (!CurrentUser.IsAdmin())
                return viewAccessDenied();

            var allAuditSummaryQuery = repository.GetAllAuditSummaryQuery();
            var filteredAuditSummaryQuery = filterData(allAuditSummaryQuery, command);
            return View(new AuditIndexViewModel
            {
                AuditSummaryQuery = filteredAuditSummaryQuery,
                RecordCount = allAuditSummaryQuery.Count()
            });
        }

        private static IQueryable<AuditSummary> filterData(IQueryable<AuditSummary> data, GridCommand command)
        {
            if (command.PageSize > 0)
            {
                data = data.Skip((command.Page - 1) * command.PageSize);
            }

            data = data.Take(command.PageSize);
            return data;
        }

For some reason, when I look at the "command" parameter in the debugger, all of its properties are null or zero. How do I get those querystring parameters such as AuditGrid-page=6 to go into that object properly?

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 06 May 2010, 02:06 PM
Hi Christopher,

Thank you for reporting this problem. I have fixed it and I am sending you the hotfix build. Apart from upgrading there is one additional thing you need to do. Check this code:

[GridAction(EnableCustomBinding = true, GridName="MyGrid")]
public ActionResult Index(GridCommand command)
{
       if (command.PageSize == 0)
       {
             command.PageSize = 10;
             command.Page = 1;
       }
}

On initial load the grid command will be empty (PageSize =0 and Page = 0). The highlighted code will check that and initialize the command properly.
You also need to specify the name of the grid in the GridAction attribute via the GridName property. This is required in order to extract the proper query string parameter e.g. "MyGrid-page". The alternative is to call PrefixUrlParameters(false) so the grid no longer adds its name before the query string parameters.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Chris
Top achievements
Rank 1
answered on 06 May 2010, 03:55 PM
Fixed! =]
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or