Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't have an answer for your issue. Including the full exception message would be helpful. There's not enough information for me to help you, but I'd check to make sure reportBase.Report.Document isn't null.</p> <p>However, I do want to comment on your code in general. Your controller action isn't following the conventions of ASP.NET MVC. It shouldn't be writing directly to the reponse stream. Firstly, it's hard to unit test. Second, it tends to make your action explode in responsibility (it's already about 4 times larger than I prefer my largest controllers to be) The Response.End is cutting the action short and the "return View()" does nothing. I would do something like:</p> <pre><code>var exportType = Request.Form["exportType"]; switch (exportType) { case "RTF": return new RtfExportResult(reportBase.Report.Document); case "TIFF": return new TiffExportResult(reportBase.Report.Document); case "XLS": return new XlsExportResult(reportBase.Report.Document); } return View("Error"); // unsupported export type </code></pre> <p>Then your XlsExportResult would look like:</p> <pre><code>public class XlsExportResult : ActionResult { private readonly Document document; public XlsExportResult(Document document) { this.document= document; } public override void ExecuteResult(ControllerContext context) { var response = context.HttpContext.Response; response.ContentType = "application/octet-stream"; response.AddHeader("Content-Disposition", "attachment;filename=report.xls"); var xlsExport = new XlsExport(); xlsExport.Export(this.document, response.OutputStream); } } </code></pre> <p>You could then write tests to exercise only the XlsExport part more easily. (I'd also find a way to hide XlsExport behind an interface.) With some creativity (adding additional prperties for things like file name, etc) you'll be able to reuse the *Result classes across your project.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload