Vote count:
0
I am trying to redirect the user to a different Action/Controller if a certain flag is found as part of the request under onActionExecuted method to bring back data from server in Excel format.
Following code does bring back data in response and i can see that using fiddler and dev. tools. However, user never gets prompted to download the file. What am i doing wrong or missing here?
protected override void OnActionExecuted(ActionExecutedContext filterContext) { base.OnActionExecuted(filterContext);
if(filterContext.HttpContext.Request.Form["isExcelExport"] != null)
{
var result = filterContext.Result as JsonResult;
if (result == null)
return;
TempData["ExportData"] = JsonConvert.SerializeObject(result.Data, Formatting.None);
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
{
controller = "Export",
action = "OutputExcel",
columns= filterContext.HttpContext.Request.Form["columnHeaders"],
title = filterContext.HttpContext.Request.Form["title"]
}));
} }
ExportController.cs
public FileResult ExportToExcel(string columns, string title)
{
//Create excel file
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
return File(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename);
}
asked 1 min ago
Issue with Excel Export not showing file prompt on onActionExecuted
Aucun commentaire:
Enregistrer un commentaire