How to pass parameters in web using mvc

Stimulsoft Reports.WEB discussion
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

As we pass parameters in web in ASP.NET like this:
StiReport report=StiWebReport1.GetReport();
report.Compile();
report.CompiledReport.DataSources["check"].Parameters["FromDate"].ParameterValue = DateTime.Parse("10/05/1999");
report.CompiledReport.DataSources["check"].Parameters["ToDate"].ParameterValue = DateTime.Parse("10/05/2012");
StiWebReport1.Report=report;


So how we can do it in MVC???????????????????????
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to pass parameters in web using mvc

Post by Vladimir »

Hello,

You can do it the same way in the GetReportSnapshot action:

Code: Select all

public ActionResult GetReportSnapshot()
    {
        StiReport report = new StiReport();
        report.Load(Server.MapPath("~/Content/SimpleList.mrt"));

        report.Compile();
        report.CompiledReport.DataSources["check"].Parameters["FromDate"].ParameterValue = DateTime.Parse("10/05/1999");
        report.CompiledReport.DataSources["check"].Parameters["ToDate"].ParameterValue = DateTime.Parse("10/05/2012");

        return StiMvcViewerFxHelper.GetReportSnapshotResult(report, this.Request);
    }
Thank you.
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

Thanx,


And how we pass parameters dynamically in mvc to stimulsoft report???
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

means how we can pass parameters from textboxes to stimulsoft reports....
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

Thanks alot.
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

Hello,
How we can pass parameters from textboxes to stimulsoft reports in mvc???
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to pass parameters in web using mvc

Post by Vladimir »

Hello,

For example, you can store submit values in the session:

View Model (ViewerFx.aspx):

Code: Select all

    

    
    
    
    

    
Controller (HomeController.cs):

Code: Select all

    public ActionResult Submit(string date1, string date2)
    {
        this.Session["date1"] = date1;
        this.Session["date2"] = date2;

        return View("ViewerFx");
    }

    public ActionResult GetReportSnapshot()
    {
        StiReport report = new StiReport();
        report.Load(Server.MapPath("~/Content/MyReport.mrt"));

        report.Compile();

        string date1 = this.Session["date1"] as string;
        string date2 = this.Session["date2"] as string;

        report.CompiledReport.DataSources["check"].Parameters["FromDate"].ParameterValue = DateTime.Parse(date1);
        report.CompiledReport.DataSources["check"].Parameters["ToDate"].ParameterValue = DateTime.Parse(date2);

        return StiMvcViewerFxHelper.GetReportSnapshotResult(report, this.Request);
    }
Thank you.
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

Hey, it worked...
Thanks...
But when page renders first time it will give error, as because of no parameters are passed.. but after that session created so error not comes..
ERROR IS:
"Value cannot be null.
Parameter name: String"

Any way to remove this error?
But your code works fine after that...

Thanks...
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

How to pass parameters in web using mvc

Post by Vladimir »

Hello,

You can use the following condition:

Code: Select all

public ActionResult GetReportSnapshot()
    {
        StiReport report = new StiReport();
        report.Load(Server.MapPath("~/Content/MyReport.mrt"));

        report.Compile();

        string date1 = this.Session["date1"] as string;
        string date2 = this.Session["date2"] as string;

        if (!string.IsNullOrEmpty(date1)) report.CompiledReport.DataSources["check"].Parameters["FromDate"].ParameterValue = DateTime.Parse(date1);
        if (!string.IsNullOrEmpty(date2)) report.CompiledReport.DataSources["check"].Parameters["ToDate"].ParameterValue = DateTime.Parse(date2);

        return StiMvcViewerFxHelper.GetReportSnapshotResult(report, this.Request);
    }
or

Code: Select all

public ActionResult GetReportSnapshot()
    {
        StiReport report = new StiReport();
        report.Load(Server.MapPath("~/Content/MyReport.mrt"));

        report.Compile();

        string date1 = this.Session["date1"] as string;
        string date2 = this.Session["date2"] as string;

        if (string.IsNullOrEmpty(date1)) date1 = "some default date1";
        if (string.IsNullOrEmpty(date2)) date1 = "some default date2";

        report.CompiledReport.DataSources["check"].Parameters["FromDate"].ParameterValue = DateTime.Parse(date1);
        report.CompiledReport.DataSources["check"].Parameters["ToDate"].ParameterValue = DateTime.Parse(date2);

        return StiMvcViewerFxHelper.GetReportSnapshotResult(report, this.Request);
    }
Thank you.
rohit
Posts: 15
Joined: Wed Jun 13, 2012 4:18 am
Location: Chandigarh

How to pass parameters in web using mvc

Post by rohit »

I do not want to give some default value...
I just want that when first time report loads on web then it will be blank, only showing report viewer(not report) in browser.
After that when value passed from textbox then it will load the report.
But it does not working.
And your code:
v
not working
it gives following error:
The parameterized query '(@FromDate int)SELECT CompanyClients.FirstName, CompanyClients.L' expects the parameter '@FromDate', which was not supplied.

As, it is obvious.. because no parameters are paased when reports render in web first time..

Thanks.
Post Reply