Problems with the return on an ActionResult method using Syncfusion to create/download Word document

  Uncategorised

In my ASP.NET MVC web app, I have an action that creates and downloads a .docx document and redirects to another action or goes directly to a view.

The problem: after downloading the document, the web doesn’t get redirected to the view.

This is my the code:

Controller:

public ActionResult CrearOrdenInterna()
{                    
    string ot = "mystring";
    OrdenDeTrabajo(ot);                    
                
    return View("myview");
}

public void OrdenDeTrabajo(string ot)
{
    // Creates an instance of WordDocument class
    WordDocument document = new WordDocument();
    IWSection section = document.AddSection();
    //section.AddParagraph().AppendText("Horizontal merging of Table cells");

    IWTable table = section.AddTable();
    table.ResetCells(6, 4);

    // Adds content to table cell
    table[0, 0].AddParagraph().AppendText("First row, First cell");
    table[0, 1].AddParagraph().AppendText("First row, Second cell");
    table[1, 0].AddParagraph().AppendText("Second row, First cell");
    table[1, 1].AddParagraph().AppendText("Second row, Second cell");
 
    document.Save("document.docx",FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment);
    document.Close();
}

Source: Visual Studio Questions

LEAVE A COMMENT