 <p>How are you calling this void function? The return paths include setting a <code>ViewBag</code> property with an error message along with modifying the response. It smells of bad design. </p> <p>I'd create a hyperlink that links to a <code>@Url.Action</code> for something like this. Note that you'd need to return a <code>FileContentResult</code> with the data UTF8-encoded rather than modifying the <code>Response</code> directly:</p> <pre><code> public async Task&lt;ActionResult&gt; Test() { WebGrid wd = new WebGrid(source: ViewBag.DynamicResult, canPage: false, canSort: false ); string griddata = wd.GetHtml().ToString(); string attachment = "attachment; filename=NativeQuery" + vartimedate + ".xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/excel"; byte[] buffer = System.Text.UTF8Encoding.UTF8.GetBytes(griddata); return File(buffer, "application/octet-stream"); } </code></pre>