rdlc报告在本地但不在服务器上运行

时间:2014-07-04 03:23:43

标签: asp.net rdlc

我有一些包含一些数据集的报告,在本地完美运行,但在服务器上我收到错误:

  

尚未指定运行报告所需的一个或多个参数。

我在这个报告上没有任何参数,所以我不明白这个错误......我在控制器中有这个代码:

    public ActionResult RunReport(int PremiseId)
    {
        LocalReport localReport = new LocalReport();
        localReport.ReportPath = Server.MapPath("~/Views/Report/PremisePricing.rdlc");

        Premise premise = _db.GetPremise(PremiseId);
        ICollection<PremisePricing> premisePricings;
        if (premise.PremiseMeters.Count() > 0)
        {
            premisePricings = premiseMeterPricingToPremisePricing(_db.FindAllPremiseMeteredPricing(premise).ToList());
        }
        else
        {
            premisePricings = _db.FindAllPremisePricing(PremiseId).ToList();
        }


        // Add your data source
        List<ReportDataSource> listDS = new List<ReportDataSource>();

        ICollection<Premise> premises = new List<Premise>();
        premises.Add(premise);
        ReportDataSource premiseDS = new ReportDataSource("Premise", premises);
        listDS.Add(premiseDS);

        ReportDataSource premisePricingDS = new ReportDataSource("PremisePricing", premisePricings);
        listDS.Add(premisePricingDS);

        ICollection<CompanyProvider> companyProviders = new List<CompanyProvider>();
        CompanyProvider companyProvider = _db.GetCompanyProvider();
        companyProviders.Add(companyProvider);
        ReportDataSource companyProviderDS = new ReportDataSource("CompPro", companyProviders);
        listDS.Add(companyProviderDS);

        ICollection<CompanyProviderContactManager> companyProviderContactManager = new List<CompanyProviderContactManager>();
        if (companyProvider.CompanyProviderContactManager != null)
        {
            companyProviderContactManager.Add(companyProvider.CompanyProviderContactManager);
        }
        ReportDataSource companyProviderContactManagerDS = new ReportDataSource("CompProContactManager", companyProviderContactManager);
        listDS.Add(companyProviderContactManagerDS);


        ICollection<Customer> customer = new List<Customer>();
        if (_db.GetPremiseProviderByPremiseId(PremiseId) != null)
        {
            Customer cust = _db.GetPremiseProviderByPremiseId(PremiseId).Customer;
            customer.Add(cust);
        }
        ReportDataSource customerDS = new ReportDataSource("Customer", customer);
        listDS.Add(customerDS);

        RenderReport(localReport, listDS, companyProvider.logo);

        return View();

    }


    private void RenderReport(LocalReport localReport, List<ReportDataSource> listDS, byte[] logo)
    {

        foreach (ReportDataSource ds in listDS)
        {
            localReport.DataSources.Add(ds);
        }

        HttpContextBase imageDirectoryPath = HttpContext;


        string reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;

        //The DeviceInfo settings should be changed based on the reportType
        string deviceInfo =
            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>11in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>0.5in</MarginLeft>" +
            "  <MarginRight>0.5in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;

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


        //Write to the outputstream
        //Set content-disposition to "attachment" so that user is prompted to take an action
        //on the file (open or save)

        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=Pricing." + fileNameExtension);
        Response.BinaryWrite(renderedBytes);
        Response.End();
    }

有什么建议吗?

0 个答案:

没有答案
相关问题