MVC 5如何在rdlc报表中使用对象 [英] MVC 5 How to use an object in rdlc report

查看:132
本文介绍了MVC 5如何在rdlc报表中使用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个问题.

我正在使用VS Community 2015和带有Entity Framework 6的MVC 5项目.我使用代码优先迁移进行数据建模.

I'm using VS Community 2015 and a MVC 5 project with Entity Framework 6. I use code first migration for data modeling.

我已经有了使用每个视图的报告.每个视图都使用C#模型作为HTML5网页来显示报告.

I allready have reports using a view for each one. Each view uses a C# model for show report as a HTML5 web page.

现在,我必须将输出发送到pdf,word,excel ...为此,我将使用RDLC,但是我不知道如何将对象模型设置为数据集.想法是发送所有已经使用视图来构建报告的对象.报告的数据不是.

Now I have to send the output to pdf, word, excel... For that I'll use RDLC but I don't know how set the object model as a dataset. The idea is send the same object that allready use the view for build the report. The data for the reports isn't.

任何想法,建议或教程该怎么做?

Any idea or suggestion or tutorial how can I do that?

我是RDLC的新手,以前从未使用过数据集.

I'm very new to RDLC and I'd never use dataset before.

谢谢

推荐答案

您可以使用ReportViewer对象将RDLC呈现为PDF或HTML.对于我的情况(如下),我需要一个PDF文档,并将其作为FileContentResult ActionResult返回.如果您希望它作为下载返回,请使用File ActionResult(我已将其注释出来供您使用).

You can use the ReportViewer object to render an RDLC to PDF or HTML. For my case (below) I wanted a PDF document and I returned it as a FileContentResult ActionResult. If you want it to return as a download use the File ActionResult (I've commented that out for your use).

public ActionResult GetPackingSlipPDF(int shipmentId)
    {
        var shipment = _inboundShipmentService.GetInboundShipmentById(shipmentId);

        Warning[] warnings;
        string mimeType;
        string[] streamids;
        string encoding;
        string filenameExtension;

        var viewer = new ReportViewer();
        viewer.LocalReport.ReportPath = @"Labels\PackingSlip.rdlc";

        var shipLabel = new ShippingLabel { ShipmentId = shipment.FBAShipmentId, Barcode = GetBarcode(shipment.FBAShipmentId) };

        viewer.LocalReport.DataSources.Add(new ReportDataSource("ShippingLabel", new List<ShippingLabel> { shipLabel }));
        viewer.LocalReport.Refresh();

        var bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

        return new FileContentResult(bytes, mimeType);

        //return File(bytes, mimeType, shipment.FBAShipmentId + "_PackingSlip.pdf");
    }

在ASP中以HTML格式呈现RDLC报告. NET MVC

这篇关于MVC 5如何在rdlc报表中使用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆