Page 1 of 2

How to pass parameters in web using mvc

Posted: Wed Jun 13, 2012 4:28 am
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???????????????????????

How to pass parameters in web using mvc

Posted: Thu Jun 14, 2012 2:29 am
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.

How to pass parameters in web using mvc

Posted: Thu Jun 14, 2012 2:42 am
by rohit
Thanx,


And how we pass parameters dynamically in mvc to stimulsoft report???

How to pass parameters in web using mvc

Posted: Thu Jun 14, 2012 2:44 am
by rohit
means how we can pass parameters from textboxes to stimulsoft reports....

How to pass parameters in web using mvc

Posted: Thu Jun 14, 2012 2:49 am
by rohit
Thanks alot.

How to pass parameters in web using mvc

Posted: Thu Jun 14, 2012 3:08 am
by rohit
Hello,
How we can pass parameters from textboxes to stimulsoft reports in mvc???

How to pass parameters in web using mvc

Posted: Fri Jun 15, 2012 2:45 am
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.

How to pass parameters in web using mvc

Posted: Fri Jun 15, 2012 4:40 am
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...

How to pass parameters in web using mvc

Posted: Fri Jun 15, 2012 5:54 am
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.

How to pass parameters in web using mvc

Posted: Fri Jun 15, 2012 6:05 am
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.