http://www.telerik.com/help/reporting/mvc-report-viewer-extension-embedding.html
I'm using telerik reports with ASP.NET MVC and trying to access a session variable, but it's always return null. session works perfectly in any other place except for below methods
private void Report4_ItemDataBound(object sender, EventArgs e)
{
ReportViewModel model = (ReportViewModel)System.Web.HttpContext.Current.Session["ReqColumns"]; // session is null here
}
private void Report4_NeedDataSource(object sender, EventArgs e)
{
ReportViewModel model = (ReportViewModel)System.Web.HttpContext.Current.Session["ReqColumns"]; // session is null here
}
5 Answers, 1 is accepted
The Session is not available in the Web API where the report is generated, thus the value of the variable will be null. In addition, it is not recommended to use the Session. To supply data in the report, try to use an ObjectDataSource component wrapping a data retrieval method, where you can implement your logic to access data.
If you need further help, please elaborate on the scenario and the need to pass data in this way.
Regards,
Stef
Telerik
New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.
My scenario is something similar to below.
Three sql tables "tblCoutry" , "tblCity", "tblStudent" and in a asp.net mvc view i have two dropdown list showing the values of countries and cities.
User selects the Country and the city and he clicks on a submit button. Then the datasource of students is generated according to the selected values and bind to the report.
When redirecting from first page to the second page i had to keep the generated datasource in a session. How can i use a datasourceobject in this scenario?
Create a model with a static object in memory e.g. DataTable, which holds the generated data. Bind the report to this static object using an ObjectDataSource component, and finally pass the model to the view.
Thus you can avoid relying on the Session in your MVC project.
I hope this helps you.
Regards,
Stef
Telerik
New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.
I tried to create a sample but report does not show any data. I added a CoverSheetDataSet.xsd and a DataTable named "VendorSqaudCheck" to that dataset, with following columns
Comments / DateForReturn
[HttpPost]
public ActionResult Index(VendorCoverSheetFormModel model)
{
CoverSheetDataSet ds = new CoverSheetDataSet();
DataTable vSqTable = ds.Tables["VendorSqaudCheck"];
DataRow newCustomersRow = ds.Tables["VendorSqaudCheck"].NewRow();
newCustomersRow["Comments"] = model.Comments;
newCustomersRow["DateForReturn"] = model.DateForReturn;
ds.Tables["VendorSqaudCheck"].Rows.Add(newCustomersRow);
return View("Report",model);
}
Then i used objectdatasource to attach columns to the report. I'm using ASP.NET MVC with HTML 5 report viewer.
The ObjectDataSource in the report definition is not associated to the data passed in your controller at run-time.
Please take a look at the sample project attached to the following post: ASP.net MVC - Telerik Reporting error => /api/reports/clients returns “Missing report name”.
Regards,
Stef
Telerik
New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.