fra*_*nus 8 c# rdlc asp.net-mvc-5
这是我的第一个问题.
我正在使用VS Community 2015和一个带有Entity Framework 6的MVC 5项目.我使用代码优先迁移进行数据建模.
我已经有报告使用每个视图.每个视图都使用C#模型将show report作为HTML5网页.
现在我必须将输出发送到pdf,word,excel ...为此,我将使用RDLC,但我不知道如何将对象模型设置为数据集.这个想法是发送同一个已经使用视图构建报告的对象.报告的数据不是.
任何想法或建议或教程我该怎么做?
我是RDLC的新手,我之前从未使用过数据集.
谢谢
您可以使用ReportViewer对象将RDLC呈现为PDF或HTML.对于我的情况(下面),我想要一个PDF文档,然后将其作为FileContentResult ActionResult返回.如果你想让它作为下载返回,请使用File ActionResult(我已经注释了它供你使用).
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");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13878 次 |
| 最近记录: |