'How can I return a ContentResult and a FileResult in the same method?
I am working with MVC and I have the next methos which return a ContentResult, and in the same method I need to download a FileResult, the problem is the excel is downloaded with no notify the user on the browser:
[HttpPost]
public ActionResult SetReportId()
{
//Some code
var report = reportView.Report;
var reportName = report.Name;
if (!reportView.HasReportPreview)
{
var fileName = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) +
@"\Downloads\" + string.Format("{0}.{1}", reportName, "xlsx");
report.ExportToXlsx(fileName);
}
return new ContentResult
{
Content = iid.ToString(),
ContentEncoding = Encoding.UTF8,
ContentType = "text/plain"
};
}
However if I use this test method returning a FileResult the file is downloaded with a
notification on the browser:
[MvcPermissionAuthorizationFilter("Reports|1")]
[QueryLoginHandlingFilter]
public ActionResult Report()
{
//Some code
var rep = reportView.Report;
var fileName = String.Format("Report.{0}", "xlsx");
using (MemoryStream ms = new MemoryStream())
{
rep.ExportToXlsx(ms);
return ExportDocument(ms.ToArray(), "xlsx", fileName, false);
}
}
The problem is the method requires tu return a ContentResult, any hint in order to return
ContentResult besides the FileResult in the same method.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
