I have a form that is used to create a report. We use reports RDLC
, and the report is loaded on the page aspx
.
So, this is the code for Form
, for the purpose of the form, a value is set _blank
and opens in a new tab.
@using (Html.BeginForm("AssetReports", "AssetReports", FormMethod.Post, new { target = "_blank" }))
{
<div class="row mt-15">
<div class="col-md-12 text-center">
<input type="submit" class="btn btn-primary" value="Show Report" />
</div>
</div>
}
This is a controller action that redirects to the aspx report page where the report is processed and displayed.
[HttpPost]
public void AssetReports(AssetReportsDTO model, AssetReportParametersDTO reportParameters)
{
SessionHandler.AssetReport = model;
SessionHandler.AssetReportParameters = reportParameters;
switch (model.SelectedReportType)
{
case AssetReportTypesEnum.ExcessiveIdleReport:
Response.Redirect("~/Reports/AssetReports/ExcessiveIdleReport/ExcessiveIdleReport.aspx");
break;
}
}
Reports take 3.4 minutes to generate in some cases. and during this time the user interface is blocked,
We want the report to be generated in a separate stream so that the user can use the user interface when creating the report.
Is there a way in C # MVC to execute this action in a separate thread?
, NULL
Task.Factory.StartNew(() =>
{
switch (model.SelectedReportType)
{
case AssetReportTypesEnum.ExcessiveIdleReport:
Response.Redirect("~/Reports/AssetReports/ExcessiveIdleReport/ExcessiveIdleReport.aspx");
break;
}
});
:
new Thread(() =>
{
switch (model.SelectedReportType)
{
case AssetReportTypesEnum.ExcessiveIdleReport:
Response.Redirect("~/Reports/AssetReports/ExcessiveIdleReport/ExcessiveIdleReport.aspx");
break;
}
}).Start();
- , 3 4 ExcessiveIdleReport.aspx
public partial class ExcessiveIdleReport1 : Page
{
private IReportsProvider _reportsProvider;
protected void Page_Load(object sender, EventArgs e)
{
_reportsProvider = new ReportsProvider();
if (!IsPostBack)
{
try
{
var reportDetails = SessionHandler.AssetReport;
var reportParams = SessionHandler.AssetReportParameters;
var sPath = Server.MapPath("../ExcessiveIdleReport/ExcessiveIdleReport.rdlc");
var dsExcessiveReport =
_reportsProvider.GetExcessiveIdleReport(reportDetails.CompanyId, reportDetails.AssetId, reportDetails.StartDate,
reportDetails.EndDate, reportParams.SelectedIdleTime * 60);
ExcessiveIdleReportViewer.ProcessingMode = ProcessingMode.Local;
ExcessiveIdleReportViewer.LocalReport.EnableHyperlinks = true;
ExcessiveIdleReportViewer.HyperlinkTarget = "_blank";
ExcessiveIdleReportViewer.LocalReport.DataSources.Add(new ReportDataSource("ExcessiveIdleReport", dsExcessiveReport.Tables[0]));
ExcessiveIdleReportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportHeaderDetails", dsExcessiveReport.Tables[1]));
ExcessiveIdleReportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportSummary", dsExcessiveReport.Tables[2]));
ExcessiveIdleReportViewer.LocalReport.ReportPath = sPath;
ExcessiveIdleReportViewer.LocalReport.EnableExternalImages = true;
ExcessiveIdleReportViewer.LocalReport.SetParameters(param);
ExcessiveIdleReportViewer.LocalReport.Refresh();
}
catch (Exception ex)
{
ErrorDiv.InnerText = string.Format("An error occured while generating the ExcessiveIdleReport, Please contact Support with following Message: [{0}] - [{1}]", ex.Message, ex.StackTrace);
ReportContentDiv.Visible = false;
ErrorDiv.Visible = true;
}
}
}
}
Ajax.BeginForm
@using (Ajax.BeginForm("AssetReports", "AssetReports", new AjaxOptions() { HttpMethod = "POST", OnSuccess = "OpenReport"}, new { target = "_blank" }))
{
<div class="row mt-15">
<div class="col-md-12 text-center">
<input type="submit" class="btn btn-primary" value="Show Report" />
</div>
</div>
}
JS:
function OpenReport(response) {
var popup = window.open("about:blank", "_blank");
popup.location = '/TBReports/AssetReports/ExcessiveIdleReport/ExcessiveIdleReport.aspx';
}
Ajax:
Asset Reports 'Show Report', :
. View Group Reports
, .