我正在尝试使用ASP.NET MVC 5将Report Viewer for MVC集成到我的角度应用程序中。
REPORT:
查看/报表/ Index.cshtml
@model JET.Shop.Common.Models.ReportRequestModel
@using ReportViewerForMvc;
<div>
<div class="row">
<div class="col-md-5">
@using (Html.BeginForm("Index", "Report", FormMethod.Post))
{
<div class="form-group">
<label>Start Date</label>
@Html.TextBoxFor(model => model.StartDate, string.Format("{0:d}", DateTime.Now), new { @id = "startDate", @class = "datefield", type = "date" })
</div>
<div class="form-group">
<label>End Date</label>
@Html.TextBoxFor(model => model.EndDate, string.Format("{0:d}", DateTime.Now), new { @id = "endDate", @class = "datefield", type = "date" })
</div>
}
</div>
<div class="col-md-7">
<div class="form-group">
<input type="submit" value="Generate" />
</div>
</div>
</div>
<div class="row">
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)
</div>
</div>
ReportController
public class ReportController : Controller
{
// GET: Report
public ActionResult Index(ReportType reportType = ReportType.SalesOrderList)
{
ReportRequestModel model = new ReportRequestModel();
model.Type = reportType;
model.StartDate = DateTime.Now;
model.EndDate = DateTime.Now;
return PartialView(model);
}
[HttpPost]
public ActionResult Index(ReportRequestModel request)
{
List<ReportParameter> reportParams = new List<ReportParameter>();
ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;
SalesOrdersListDataSet salesOrderDataSet = new SalesOrdersListDataSet();
salesOrderDataSet.SalesOrder.AddSalesOrderRow(Guid.NewGuid(), DateTime.Now, DateTime.Now, DateTime.Now.AddDays(1), 500, 60, 440, "Complete");
salesOrderDataSet.SalesOrder.AddSalesOrderRow(Guid.NewGuid(), DateTime.Now, DateTime.Now, DateTime.Now.AddDays(1), 100, 12, 88, "Complete");
ReportDataSource reportDataSource1 = new ReportDataSource();
reportDataSource1.Name = "Report"; //Name of the report dataset in our .RDLC file
reportDataSource1.Value = salesOrderDataSet.SalesOrder;
reportViewer.LocalReport.DataSources.Add(reportDataSource1);
reportViewer.LocalReport.ReportEmbeddedResource = "JET.Shop.WebApp.Reports.SalesOrderListReport.rdlc";
reportViewer.LocalReport.SetParameters(reportParams);
ViewBag.ReportViewer = reportViewer;
return PartialView(request);
}
}
RouteConfig
routes.MapRoute(
name: "ReportController",
url: "Report/Index/{reportType}",
defaults: new { controller = "Report", action = "Index", reportType = UrlParameter.Optional }
);
$ RouteProvider
.when("/Report", {
templateUrl: "/Report/Index",
controller: "ReportController",
loginRequired: true,
requiredRoles: ["Admin"]
})
我基本上想尝试渲染这个报表查看器,但是我在控制台上遇到HTTP 500 - 内部服务器错误时遇到了困难。
我做了一些随机的试验和错误,发现如果我让我的Report / Index.cshtml只包含纯HTML(没有razor),它会呈现。但是当我在视图中包含我的@model语句时,我获得了HTTP 500.任何人都可以帮我解决这个问题吗?断点到我的控制器(GET索引)工作正常。
仅供参考我通过浏览器上的URL直接访问报告页面以进行快速测试。
有关如何处理此问题的任何建议?我的主要目标是显示一个ReportViewer,因为一旦它在视图上呈现,我就可以在那里工作。
报告/ Index.cshtml使用纯HTML工作..
@*@model JET.Shop.Common.Models.ReportRequestModel
@using ReportViewerForMvc;*@
<div>
<div class="row">
<div class="col-md-5">
@*@using (Html.BeginForm("Index", "Report", FormMethod.Post))
{
<div class="form-group">
<label>Start Date</label>
@Html.TextBoxFor(model => model.StartDate, string.Format("{0:d}", DateTime.Now), new { @id = "startDate", @class = "datefield", type = "date" })
</div>
<div class="form-group">
<label>End Date</label>
@Html.TextBoxFor(model => model.EndDate, string.Format("{0:d}", DateTime.Now), new { @id = "endDate", @class = "datefield", type = "date" })
</div>
}*@
THIS WORKS FINE!
</div>
<div class="col-md-7">
<div class="form-group">
<input type="submit" value="Generate" />
</div>
</div>
</div>
<div class="row">
@*@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)*@
</div>
</div>
答案 0 :(得分:0)
关闭此问题,
我最终根本没有使用报告查看器。我刚刚创建了一个MVC控制器,它可以从水晶报告中生成Excel / PDF。