We were able to get the report viewer to work and use it over the past few months in production without any problems.
- We have a report controller that lists the links to the reports we want to run.
- , ajax- , .
- "\ reports\Name of Report".
- SQL, , " "
- " " Crystal Report, , ViewData, , .
, , .
. , , - , Crystal Reports. , . Crystal Reports :
- file.rpt,
- aspx, Crystal Reports Report. , .
, , Crystal Reports:
- Crystal Reports Designer. .rpt . AllJobsSummaryReportLayout.rpt.
- " " - DTO, SQL.
- (DTO) , , , DTO . , , DTO, , . DTO , , , , SQL, - .
Crystal Report, AllJobsSummaryReportLayout.rpt, . , , Model DTO, :
var reportViewData = model.AllJobsSummaryQuery(startDate, endDate);
if (0 != reportViewData.Count())
{
var report = new AllJobsSummaryReportLayout();
report.SetDataSource(reportViewData);
report.SetParameterValue("startDate", startDate);
report.SetParameterValue("endDate", endDate);
ViewData["ReportData"] = report;
returnView = "AllJobsSummaryView";
}
else
returnView = "noReportView";
return View(returnView);
, varible 'report', Crystal Report AllJobsSummaryReportLayout.rpt, .
"report", , , ViewData.
AllJobsSummaryView.aspx. Crystal Reports Viewer , :
<%@ Page Title="All Jobs Summary Report" Language="C#" AutoEventWireup="true" CodeBehind="AllJobsSummaryView.aspx.cs" Inherits="V.Views.Reports.AllJobsSummaryView"%>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<form id="form1" runat="server">
<div>
<a href="/Reports" id="Report"><< Return to Report Main
Page</a><br />
<CR:CrystalReportViewer ID="ReportViewer" runat="server" AutoDataBind="True" EnableDatabaseLogonPrompt="False"
EnableParameterPrompt="False" HasCrystalLogo="False" DisplayGroupTree="False"
HasDrillUpButton="False" HasToggleGroupTreeButton="False" HasViewList="False"
HasSearchButton="False" EnableDrillDown="False" EnableViewState="True"
Height="50px" ReportSourceID="CrystalReportSource1" Width="350px" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="AllJobsSummaryReportLayout.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace V.Views.Reports
{
public partial class AllJobsSummaryView : ViewPage
{
protected void Page_Init(object sender, EventArgs e)
{
ReportViewer.ReportSource = ViewData["ReportData"];
}
protected void Page_Unload(object sender, EventArgs e)
{
((AllJobsSummaryReportLayout)ViewData["ReportData"]).Close();
((AllJobsSummaryReportLayout)ViewData["ReportData"]).Dispose();
}
}
}
_Unload , , Crystal Reports. " , ".
.