将参数传递给MVC4数据集中的查询以获取RDLC报告

时间:2014-02-27 19:33:56

标签: c# asp.net-mvc-4 rdlc dynamic-rdlc-generation

注意:我在MVC4中使用Microsoft Reports

我在VisualStudio中创建了一个名为DataSet1.xsd的DataSet,其中我添加了一个名为'st'的TableAdapter,并在该tableadapter中创建了名为dt1的DataTabledt1 GetData()Fill(@p0)中有两种方法。

我创建了一个新的RDLC报告,该报告绑定到DataSet1 现在,当我尝试生成报告时,它显示以下错误

One or more parameters required to run the report have not been specified.

我不知道如何在运行时将参数传递给报告

控制器

public ActionResult Report(string id)
    {
        var lr = new LocalReport();
        var path = Path.Combine(Server.MapPath("~/Reports"), "Report1.rdlc");
        if (System.IO.File.Exists(path))
        {
            lr.ReportPath = path;
        }
        else
        {
            return View("Index");
        }

        var reportType = id;
        string mimeType;
        string encoding;
        string fileNameExtension;



        var deviceInfo =

        "<DeviceInfo>" +
        "  <OutputFormat>" + id + "</OutputFormat>" +
        "  <PageWidth>8.5in</PageWidth>" +
        "  <PageHeight>11in</PageHeight>" +
        "  <MarginTop>0.5in</MarginTop>" +
        "  <MarginLeft>1in</MarginLeft>" +
        "  <MarginRight>1in</MarginRight>" +
        "  <MarginBottom>0.5in</MarginBottom>" +
        "</DeviceInfo>";

        Warning[] warnings;
        string[] streams;

        var renderedBytes = lr.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);


        return File(renderedBytes, mimeType);
        }
}

我尝试了以下添加参数的方法,但没有成功

var param0 = new ReportParameter("p0", "1");
rl.SetParameters(new[]{param0});

0 个答案:

没有答案
相关问题