skip to Main Content

I’m working on a page that is used as a survey and after the user ends filling the parameters, there is a button that calls an action result called "Registro" using HTTPOST, then, it executes several code lines till it gets to the line that saves the excel file:

workbook.SaveAs("Respuestas.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.Open);

but after that code line, the button seems to ignore the next part of the code, that is:

return RedirectToAction("Gracias", "Home");

I used breakpoints and the code is reading that part, but it just doesn’t redirect to the action, why?

I’ve tried to delete the workbook saveas line and the return line works perfectly; i don’t understand what i have to do in order to download the desired file AND redirect to another page.
For the excel part i’m using a library called Syncfusion.

2

Answers


  1. Your controller can only return one result. In this case workbook.SaveAs sets the HTTP Response to a file and returns this to your client. You can’t redirect thereafter because the response has already been sent. If you want to achieve a redirect you will have to solve this another way. Javascript would probably be your best option.

    Login or Signup to reply.
  2. Greetings from Syncfusion.

    The behavior of Syncfusion XlsIO in web application is, when the workbook is saved, response ends after writing the Excel file. Hence the redirection to next action does not take place. We have prepared a simple sample with workaround to redirect to next action.

    This sample can be downloaded from below link.

    Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/T413265_MVC-1487881320.zip

    Kindly try and let us know if this helps.

    Regards,
    Keerthi.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search