At present our MVCxGridView export mechanism has some limitations: it is impossible to export a lot of filtered data, because the mechanism requests all data from a database and then filters it. Thus, a request can be fulfilled, and the 'System.OutOfMemoryException' exception occurs. As a solution, request filtered data yourself and export it using the XtraReports Suite. This example demonstrates how you can do this using LINQ-to-SQL.
To pass the FilterExpression to a Controller's Action, obtain and save it to GridView CustomJSProperties in CustomJSProperties:
[C#]settings.CustomJSProperties=(s,e)=>{ASPxGridViewgrid=(ASPxGridView)s;e.Properties["cpGridFilterExpression"]=grid.FilterExpression;};settings.CustomJSProperties=Sub(s,e)DimgridAsASPxGridView=DirectCast(s,ASPxGridView)e.Properties("cpGridFilterExpression")=grid.FilterExpressionEndSub
When a user clicks the Export data, take the filter expression from GridView CustomJSProperties and add it to the collection of jQuery selector parameters.
[JavaScript]function OnClick(s, e){var actionParams = $("form").attr("action").split("?filterString="); actionParams[1] = gvDataBindingToLinq.cpGridFilterExpression; $("form").attr("action", actionParams.join("?filterString="));}
The XtraReport class instance that's used in this Code Example is added as described in the Lesson 1 - Create a Static Report in ASP.NET MVC tutorial. The report controls are bound to data using the Embedded Fields (Mail Merge) feature.
You can learn more about approaches used in this example in the following resources:
How to: Create a Table Report
How to create a web based report at runtime
How to convert the CriteriaOperator to a lambda expression, so, the latter expression can be used in the IQueriable source
GridView Extension - Provide the capability to export large LINQ data
Walkthrough: Installing the AdventureWorks Database
Question Comments
Added By: Kevin Turpin 1 at: 2/10/2016 11:50:47 AM OK, i absolutely love that i can do this, nicely done.Added By: John John Smith at: 3/23/2016 9:39:34 AM There really isn't any difference between binding to an XtraReport just to export, and using a datatable is there? The code in the home controller looks almost identical.
It doesn't matter how I filter my data, if it goes above the .Net 2gb limit then it throw the out of memory exception error.Added By: Vladimir (DevExpress Support) at: 3/23/2016 12:59:31 PM
Hello,
To process your recent post more efficiently, I created a separate ticket on your behalf: T359906: The out of memory exception occurs when GridVIew data in being exported. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.