1

注意:我在 MVC4 中使用 Microsoft Reports

DataSet在 VisualStudio 中创建了一个名为 DataSet1.xsd,我在其中添加了一个TableAdapter名为“st”,并在该表适配器中创建了DataTable名为 dt1。dt1 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});
4

0 回答 0