Как визуализировать отчеты SSRS, расположенные на сервере SSRS в браузере в ASP.net MVC 5, используя частичные представления?
У меня есть выпадающий список, который выбирает один из отчетов, которые я хочу сделать. Итак, это будет динамично. Я видел разработчиков, использующих элемент управления ReportViewer из веб-форм в MVC, использующий iframe или пакет NuGet под названием reportViewerforMvc. Но я не смог заставить его работать, так как я не хочу обновлять всю страницу, просто хочу обновить содержимое одного div, который будет содержать отчет. Я создал контроллер, который будет вызывать ajax.
Вот мои обновления до сих пор:
public ActionResult ReportPartial(string reportName)
{
var reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Remote;
reportViewer.SizeToReportContent = true;
reportViewer.ZoomMode = ZoomMode.PageWidth;
reportViewer.Width = Unit.Percentage(100);
reportViewer.Height = Unit.Percentage(100);
reportViewer.AsyncRendering = true;
var reportInfo = GetReportInfo(reportName);
reportViewer.ServerReport.ReportServerUrl = new Uri(reportInfo.Item1);
reportViewer.ServerReport.ReportPath = reportInfo.Item2;
ViewBag.ReportViewer = reportViewer;
var reportView = PartialView("ReportPartial");
return reportView;
}
Частичное представление просто отображает отчет на основе элемента управления веб-форм.
@using ReportViewerForMvc;
<div id="reportDIV">
@if (ViewBag.ReportViewer != null)
{
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { scrolling = "no" })
}
</div>
Со стороны клиента Ajax вызывает метод ReportPartial Action, который должен визуализировать, возвращать представление, или это то, что я ожидал.
function generateReport(reportName) {
$('#reportView').empty();
$.ajax({
url: baseUrl + 'Report/ReportPartial',
async:true,
type: "POST",
data: JSON.stringify({ reportName: reportName}),
dataType: "html",
contentType: "application/json; charset=utf-8",
success: function (result) {
$('#reportView').html(result);
$('#reportView').show();
},
error: function (jqXHR, status, errorThrown) {
kendo.alert("Cannot connect to Sever! Contact Administrator");
}
});
Хотя я не мог заставить его работать, он все время говорит, что ресурс не найден, и я не знаю, что я делаю.
Вот файл ReportViewerWebForm.aspx, который добавляет пакет NuGet, который отвечает за создание iframes
<!DOCTYPE html>
<div id="report" runat="server" style="margin: 0px; padding: 0px;">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="ReportViewerForMvc" Name="ReportViewerForMvc.Scripts.PostMessage.js" />
</Scripts>
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>
</div>
</form>
</div>
</html>
Есть ошибка во время выполнения, говорящая, что он не может проанализировать rsweb.reportViewer.
Консоль зарегистрировала эту ошибку
Любая помощь будет оценена.