Asp.net mvc 在ASP.NET MVC中以HTML呈现RDLC报告
我想在ASP.NET MVC项目中以HTML格式呈现RDLC报告 在的帮助下,我成功地制作了一个原型,以PDF、Excel和TIFF图像呈现RDLC报告。但是我很惊讶HTML不是Asp.net mvc 在ASP.NET MVC中以HTML呈现RDLC报告,asp.net-mvc,reporting,reportviewer,rdlc,localreport,Asp.net Mvc,Reporting,Reportviewer,Rdlc,Localreport,我想在ASP.NET MVC项目中以HTML格式呈现RDLC报告 在的帮助下,我成功地制作了一个原型,以PDF、Excel和TIFF图像呈现RDLC报告。但是我很惊讶HTML不是LocalReport.Render()中默认的可用格式之一 我遇到了,它描述了一个启用HTML4.0呈现格式的技巧,但我认为这只适用于ReportViewer控件(尽管我可能错了) 问题是,在MVC中,如何像ReportView那样以HTML格式呈现RDLC报告(请参见下面的屏幕截图) 您可以使用ReportViewe
LocalReport.Render()
中默认的可用格式之一
我遇到了,它描述了一个启用HTML4.0呈现格式的技巧,但我认为这只适用于ReportViewer
控件(尽管我可能错了)
问题是,在MVC中,如何像ReportView
那样以HTML格式呈现RDLC报告(请参见下面的屏幕截图)
您可以使用ReportViewer对象将RDLC呈现为PDF或HTML格式。对于我的案例(如下),我想要一个PDF文档,并将其作为FileContentResult ActionResult返回。如果您希望它作为下载返回,请使用文件ActionResult(我已经将其注释出来供您使用)
public ActionResult getpackingsplattdf(int-shipmentId)
{
var Shipping=_inboundShipmentService.GetInboundShipmentById(shipmentId);
警告[]警告;
字符串模拟类型;
字符串[]流线;
字符串编码;
字符串文件名扩展名;
var viewer=new ReportViewer();
viewer.LocalReport.ReportPath=@“Labels\packingsslip.rdlc”;
var shipLabel=new ShippingLabel{ShipmentId=shipping.FBAShipmentId,Barcode=GetBarcode(shipping.FBAShipmentId)};
Add(newreportdatasource(“ShippingLabel”,newlist{shipplabel}));
viewer.LocalReport.Refresh();
var bytes=viewer.LocalReport.Render(“PDF”、null、out-mimeType、out-encoding、out-filenameExtension、out-streamid、out-warnings);
返回新的FileContentResult(字节,mimeType);
//返回文件(字节,mimeType,shipping.FBAShipmentId+“_packingsslip.pdf”);
}
我很久以前就把这个项目组合起来了
从内存中应该有rdlc和PDF的html呈现这是一个简单的任务。您可以按照以下步骤操作
public class ReportData
{
public ReportData()
{
this.ReportParameters = new List<Parameter>();
this.DataParameters = new List<Parameter>();
}
public bool IsLocal { get; set; }
public string ReportName { get; set; }
public List<Parameter> ReportParameters { get; set; }
public List<Parameter> DataParameters { get; set; }
}
public class Parameter
{
public string ParameterName { get; set; }
public string Value { get; set; }
}
<rsweb:ReportViewer ID="ReportViewerRSFReports" runat="server" AsyncRendering="false"
Width="1271px" Height="1000px" >
</rsweb:ReportViewer>
public partial class ReportView : ReportBasePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RenderReportModels(this.ReportDataObj);
}
}
private void RenderReportModels(ReportData reportData)
{
RASolarERPData dal = new RASolarERPData();
List<ClosingInventoryValuation> objClosingInventory = new List<ClosingInventoryValuation>();
// Reset report properties.
ReportViewerRSFReports.Height = Unit.Parse("100%");
ReportViewerRSFReports.Width = Unit.Parse("100%");
ReportViewerRSFReports.CssClass = "table";
// Clear out any previous datasources.
this.ReportViewerRSFReports.LocalReport.DataSources.Clear();
// Set report mode for local processing.
ReportViewerRSFReports.ProcessingMode = ProcessingMode.Local;
// Validate report source.
var rptPath = Server.MapPath(@"./Report/" + reportData.ReportName +".rdlc");
//@"E:\RSFERP_SourceCode\RASolarERP\RASolarERP\Reports\Report\" + reportData.ReportName + ".rdlc";
//Server.MapPath(@"./Report/ClosingInventory.rdlc");
if (!File.Exists(rptPath))
return;
// Set report path.
this.ReportViewerRSFReports.LocalReport.ReportPath = rptPath;
// Set report parameters.
var rpPms = ReportViewerRSFReports.LocalReport.GetParameters();
foreach (var rpm in rpPms)
{
var p = reportData.ReportParameters.SingleOrDefault(o => o.ParameterName.ToLower() == rpm.Name.ToLower());
if (p != null)
{
ReportParameter rp = new ReportParameter(rpm.Name, p.Value);
ReportViewerRSFReports.LocalReport.SetParameters(rp);
}
}
//Set data paramater for report SP execution
objClosingInventory = dal.ClosingInventoryReport(this.ReportDataObj.DataParameters[0].Value);
// Load the dataSource.
var dsmems = ReportViewerRSFReports.LocalReport.GetDataSourceNames();
ReportViewerRSFReports.LocalReport.DataSources.Add(new ReportDataSource(dsmems[0], objClosingInventory));
// Refresh the ReportViewer.
ReportViewerRSFReports.LocalReport.Refresh();
}
}
@using (Html.BeginForm("Login"))
{
@Html.DropDownList("ddlYearMonthFormat", new SelectList(ViewBag.YearMonthFormat, "YearMonthValue", "YearMonthName"), new { @class = "DropDown" })
Stock In Transit: @Html.TextBox("txtStockInTransit", "", new { @class = "LogInTextBox" })
<input type="submit" onclick="return ReportValidationCheck();" name="ShowReport"
value="Show Report" />
}
function ReportValidationCheck() {
var url = $('#hdUrl').val();
var yearmonth = $('#ddlYearMonthFormat').val();
var stockInTransit = $('#txtStockInTransit').val()
if (stockInTransit == "") {
stockInTransit = 0;
}
if (yearmonth == "0") {
alert("Please Select Month Correctly.");
}
else {
//url = url + "dpSpYearMonth=" + yearmonth + ",rpYearMonth=" + yearmonth + ",rpStockInTransit=" + stockInTransit;
url = "../Reports/ReportView.aspx?rptmode=local&reportname=ClosingInventory¶meters=dpSpYearMonth=" + yearmonth + ",rpYearMonth=" + yearmonth + ",rpStockInTransit=" + stockInTransit;
var myframe = document.getElementById("ifrmReportViewer");
if (myframe !== null) {
if (myframe.src) {
myframe.src = url;
}
else if (myframe.contentWindow !== null && myframe.contentWindow.location !== null) {
myframe.contentWindow.location = url;
}
else { myframe.setAttribute('src', url); }
}
}
return false;
}
key="UnobtrusiveJavaScriptEnabled" value="true"
verb=“*”path=“Reserved.ReportViewerWebControl.axd”type=“Microsoft.Reporting.WebForms.HttpHandler,Microsoft.ReportViewer.WebForms,Version=10.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”
我也在尝试实现这一点,但我的问题是我无法在数据菜单中找到“显示数据源”。你能给我一个指导吗?我最终使用了“报表向导”。ServerReport.Render()支持“HTML4.0”,但LocalReport.Render()不支持。这会生成一个PDF文件-OP需要一个HTML文档
LocalReport.Render()
不支持ReportViewer 2010中的HTML。链接的repo中只有Excel和PDF呈现。
public ActionResult ReportViewer()
{
ViewData["reportUrl"] = "../Reports/View/local/ClosingInventory/";
return View();
}
@using (Html.BeginForm("Login"))
{
@Html.DropDownList("ddlYearMonthFormat", new SelectList(ViewBag.YearMonthFormat, "YearMonthValue", "YearMonthName"), new { @class = "DropDown" })
Stock In Transit: @Html.TextBox("txtStockInTransit", "", new { @class = "LogInTextBox" })
<input type="submit" onclick="return ReportValidationCheck();" name="ShowReport"
value="Show Report" />
}
frameborder="0" width="1000"; height="1000"; style="overflow:hidden;" scrolling="no"
function ReportValidationCheck() {
var url = $('#hdUrl').val();
var yearmonth = $('#ddlYearMonthFormat').val();
var stockInTransit = $('#txtStockInTransit').val()
if (stockInTransit == "") {
stockInTransit = 0;
}
if (yearmonth == "0") {
alert("Please Select Month Correctly.");
}
else {
//url = url + "dpSpYearMonth=" + yearmonth + ",rpYearMonth=" + yearmonth + ",rpStockInTransit=" + stockInTransit;
url = "../Reports/ReportView.aspx?rptmode=local&reportname=ClosingInventory¶meters=dpSpYearMonth=" + yearmonth + ",rpYearMonth=" + yearmonth + ",rpStockInTransit=" + stockInTransit;
var myframe = document.getElementById("ifrmReportViewer");
if (myframe !== null) {
if (myframe.src) {
myframe.src = url;
}
else if (myframe.contentWindow !== null && myframe.contentWindow.location !== null) {
myframe.contentWindow.location = url;
}
else { myframe.setAttribute('src', url); }
}
}
return false;
}
key="UnobtrusiveJavaScriptEnabled" value="true"