This is a migrated thread and some comments may be shown as answers.
Session is null in telerik reporting
5 Answers 137 Views
This is a migrated thread and some comments may be shown as answers.
Chamara
Top achievements
Rank 1
Chamara asked on 19 Nov 2013, 04:24 AM

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

Sort by
0
Stef
Telerik team
answered on 21 Nov 2013, 03:25 PM
Hello Chamara,

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.

0
Chamara
Top achievements
Rank 1
answered on 22 Nov 2013, 02:41 AM
hello stef!

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?
0
Stef
Telerik team
answered on 22 Nov 2013, 07:25 PM
Hello Chamara,

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.

0
Chamara
Top achievements
Rank 1
answered on 07 Jan 2014, 02:42 AM
hi! 

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.
0
Stef
Telerik team
answered on 09 Jan 2014, 06:48 PM
Hi Chamara,

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.

Asked by
Chamara
Top achievements
Rank 1
Answers by
Stef
Telerik team
Chamara
Top achievements
Rank 1
Share this question
or