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

[Solved] Customer Server Binding - Paging Problems

2 Answers 88 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.
Joni
Top achievements
Rank 1
Joni asked on 23 Aug 2011, 02:59 PM
Hi,
I have tried to implement paging manually, following the Custom Server Binding example for the Grid control. It has been unsuccessful.
The first load populates the grid without a problem. If I click a page number in the footer, it throws an exception:
The view 'CustomServerBinding' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/SalesGrid/CustomServerBinding.aspx
~/Views/SalesGrid/CustomServerBinding.ascx
~/Views/Shared/CustomServerBinding.aspx
~/Views/Shared/CustomServerBinding.ascx
~/Views/SalesGrid/CustomServerBinding.cshtml
~/Views/SalesGrid/CustomServerBinding.vbhtml
~/Views/Shared/CustomServerBinding.cshtml
~/Views/Shared/CustomServerBinding.vbhtml


My code is as follows:
The Controller:
    public class SalesGridController : Controller
    {
        private AdventureWorksLT2008Entities db = new AdventureWorksLT2008Entities();
 
        //
        // GET: /SalesGrid/
 
        public ViewResult Index()
        {
            ViewData["total"] = db.SalesOrderHeader.ToList().Count;
 
            return View(db.SalesOrderHeader.ToList());
        }
 
        [GridAction(GridName = "Grid")]
        public ActionResult CustomServerBinding(GridCommand command)
        {
            IEnumerable data = GetServerData(!IsEmptyCommand(command) ? command : new GridCommand());
            return View(data);
        }   
 
        private IEnumerable GetServerData(GridCommand command)
        {
            IQueryable<SalesOrderHeader> query = from s in db.SalesOrderHeader.Include(sod => sod.SalesOrderDetail)
                                                 select s;
 
            query.ApplyFiltering(command.FilterDescriptors);
            ViewData["total"] = query.Count<SalesOrderHeader>();
            query.ApplyPaging(command.Page, command.PageSize);
 
            return query.ToList<SalesOrderHeader>();
        }
etc.

The View:
@model IEnumerable<EFAdvWorks.SalesOrderHeader>
 
@{
    ViewBag.Title = "Index";
}
 
<h2>Index</h2>
 
@(Html.Telerik().Grid<EFAdvWorks.SalesOrderHeader>()
                                .Name("grid")
                                .BindTo(Model)
                                .Columns(columns =>
                                {
                                    columns.Bound(s => s.SalesOrderID).Width(200);
                                    columns.Bound(s => s.ShipDate).Format("{0:dd/MM/yyyy}").Width(200);
                                })
                                .DataBinding(dataBinding => dataBinding.Server().Select("CustomServerBinding", "SalesGrid"))
                                .Pageable(settings => settings.Total((int)ViewData["total"]))
                                .EnableCustomBinding(true)
                                .Filterable()
)

Some guidance would be appreciated greatly.
Cheers

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 23 Aug 2011, 03:27 PM
Hi Joni,

The cause for the error you are getting is that there is not CustomServerBinding
view. If you look at the custom server binding online demo, you may noticed that the actual view which is loaded is the initial view. If you want to use different Action as select route you may explicitly render the initial view which in your case is Index view:
 

public ActionResult CustomServerBinding(GridCommand command)
{
    IEnumerable data = GetServerData(!IsEmptyCommand(command) ? command : new GridCommand());
    return View("Index", data);
}
Regards,
Rosen
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Joni
Top achievements
Rank 1
answered on 24 Aug 2011, 12:42 AM
Thanks Rosen. I knew that was the case, I just did not know how to rectify it. I'll try your solution and am confident that it will work.

Cheers
Tags
Grid
Asked by
Joni
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Joni
Top achievements
Rank 1
Share this question
or