We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

MVC Grid paging?

Thread ID:

Created:

Updated:

Platform:

Replies:

88741 Aug 10,2009 08:03 PM UTC Aug 28,2009 09:36 AM UTC ASP.NET MVC (Classic) 8
loading
Tags: Grid
William B. Morrison
Asked On August 10, 2009 08:03 PM UTC

I bought the ASP.NET MVC product today and am trying to get a paging grid working. My controller action has the following in it:

GridPropertiesModel gridModel = new GridPropertiesModel()
{
DataSource = rawAssets,
PagingSortingMapper = "PagingAction",
Caption = "Assets",
AllowPaging = true,
PageSize = 10,
AllowSorting = true,
HeaderText = { "Id", "Name", "Identifier", "Locked By" },
};

The PagingAction referred to is defined for that controller as follows:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PagingAction(PagingParams args)
{
...
}

When I click on a page number and put a breakpoint in the PagingAction method, it is not hit. When I put a breakpoint in the method that contains the grid model definition statement above, that breakpoint is hit. It is not getting to the paging action at all but rather is calling the action that sets up the grid.

- Why is this?
- Is the MVC grid dependent on Linq?
- How is the paging done? I don't see in the examples where the page numbers are relevant. We are using NHibernate for data access.

Thank you...

Benny

Balaji K [Syncfusion]
Replied On August 11, 2009 11:06 AM UTC

Hi Benny,

Thank you for choosing Syncfusion Products.

The Paging is handled by the Grid automatically. The paging request is sent to the action result specified in the PagingSortingMapper and that would return an actionresult of type GridHtmlActionResult.

Please find the code snippet below

[Controller]

GridPropertiesModel gridModel = new GridPropertiesModel()
{
DataSource = rawAssets,
PagingSortingMapper = "PagingAction",
Caption = "Assets",
AllowPaging = true,
PageSize = 10,
AllowSorting = true,
HeaderText = { "Id", "Name", "Identifier", "Locked By" },
};

AcceptVerbs(HttpVerbs.Post)]
public ActionResult getSort()
{
var sortAction = new GridHtmlActionResult();
//set the datasource
sortAction.GridModel.DataSource = rawAssets;
return sortAction;
}

Note:
The sample should be running from the full path
eg:
http://localhost:52212/home/index

Generally the default application will look like this and this case it will not page.
http://localhost:52212/Default.aspx

MVC grid is not dependent on Linq and works with any kind of IEnumerable data source.

Please let us know if this helps.

Regards,
Balaji.

William B. Morrison
Replied On August 11, 2009 02:04 PM UTC

Thanks for the reply, though that's not exactly what I was pointing out. I've looked at the paging and sorting examples that come with the product and modeled my implementation after it. Your example is odd - the PagingSortingMapper action in your example code that you posted is PagingAction() (if I remember correctly) but the example method you provide is named getSort(). From your API for the GridPropertiesModel:

//
// Summary:
// Gets or sets PagingSortingMapper
//
// Remarks:
// Specifies the Action Method URL which maps Sorting or/and paging action to
// Grid.

I would assume that the PagingSortingMapper is simply the action method to invoke when paging or sorting, correct? I posted code that showed that I was doing this and noted that I could not get the application to hit a breakpoint in the action method defined in the PagingSortingMapper property. Rather, the application goes to the Index() action method in the code that I posted. Why is the Action defined in that property not being invoked?

Thanks...

Benny

William B. Morrison
Replied On August 11, 2009 02:08 PM UTC

I meant to also point out that when I debug the examples application that is provided with the product, a breakpoint in the the PagingAction *is* hit when appropriate. Am I missing something in the view? I looked and don't believe so but may have missed something.

Thx,

Benny

William B. Morrison
Replied On August 11, 2009 06:23 PM UTC

OK - I got the paging action to be invoked - I had to reference it in the PagingSortingMapper with the controller as well - so '/Inventory/PagingAction' worked but 'PagingAction' and 'Inventory/PagingAction' did not.

Now, however, the grid is still not paging. Your example creates a List instance with a large number of mock objects each time through the Paging() and PagingAction() methods. StudentContext is a regular POCO as is Student. The only difference is that a ToList() extension method is called in the Paging() method. I've done this - except I get a list of POCO objects via NHibernate instead of mocking them up. I've even replicated the ToList() call as well but no pagination is occurring. I use a strongly typed collection in my code (AssetInfoCollection) but call ToList() on it in each method just as your example code does to ensure that I'm sending a List.

From what I understand from your examples the grid should handle the pagination given all of the data (though I'm not certain this is performant if this is the case) - this should be working, but it is not.

Here are the two methods from my controller:
==============
[RequiresDBSession]
public ActionResult Index()
{
if (ClientSession == null)
{
return View();
}
AssetInfoCollection rawAssets = null;
using (DatabaseSession.Connect())
{
rawAssets = AssetDAO.Instance().GetAllInfos(DatabaseSession);
}

GridPropertiesModel gridModel = new GridPropertiesModel()
{
DataSource = rawAssets.ToList(),
PagingSortingMapper = "/Inventory/PagingAction",
Caption = "Assets",
AllowPaging = true,
PageSize = 10,
PageCount = 10,
AllowSorting = true
};
ViewData["GridModel"] = gridModel;
return View();
}

[RequiresDBSession]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PagingAction(PagingParams args)
{
AssetInfoCollection data = new AssetInfoCollection();
using (DatabaseSession.Connect())
{
data = AssetDAO.Instance().GetAllInfos(DatabaseSession);
}

ActionResult result = data.ToList().GridActions();
return result;
}

==============
- Are there any extension methods being called on the data being sent into the grid that we perhaps are masking for some reason?
- Do you send in all of the data each time? It appears that this is the case.

Thanks...

Benny



William B. Morrison
Replied On August 11, 2009 07:57 PM UTC

Yet another post :)

Now it appears that I can get paging to work within the sample application from SyncFusion with my objects but only if they are simple objects. If I use an object from my BOM that only has simple properties - no collections - it works fine. If it has a collection on it - initialized or not and it doesn't matter if it has data in it - the grid will not render. It renders the first page fine but when you attempt to page or sort the grid only partially renders - lines are missing and you cannot select a row in it.

I can reproduce this by creating a DTO object as a wrapper for my BOM object with no collections on it. This will work - I can then add any type of collection to cause the strange rendering - I used a List and populated it with a couple of strings.

Plus I still don't know what the difference is in the MVC application I wrote from scratch and the sample from SyncFusion but I believe there is a difference causing it not to page. I went through the installation page step by step and it seems to be fine as far as base functionality.

Thanks...

Benny

Daniel Jebaraj [Syncfusion]
Replied On August 13, 2009 01:38 AM UTC

Hi Benny,

Will it be possible to share the sample?

Thanks,
Daniel

William B. Morrison
Replied On August 17, 2009 11:57 AM UTC

No, it's very tightly integrated with our infrastructure.

I mentioned in the last post that I got the paging working - it had to do with having collections on the objects bound to the grid. That could be an issue as well as the fact that it appears that all the data must be available to the grid at any one point in time to page/sort/group.

Thx,

Benny

Balaji M [Syncfusion]
Replied On August 28, 2009 09:36 AM UTC

Hi Benny,

Thank you for your patience.

We need to analyze more on this issue and we will update you with more details with in two business days.

Regards,
M. Balaji.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;