Download to excel using MVC is not working in Server
<p>I need to give download option in MVC for that i have returned one function its generate the excel and downloaded in local but after deployed in server its redirecting but generate the excel file. </p>

<p>My Codes</p>

<p>Views</p>

<pre><code>&lt;a href="/Report/StockOnHandToExcel" style="font-weight: bold" &gt;Export To Excel&lt;/a&gt;
</code></pre>

<p>Controller</p>

<pre><code>public void StockOnHandToExcel()
   {
        try
        {
            var dt = DataTableClass.ToDataTable(_report.StockOnHandExcelList());
            var stream = ExcelUtility.GetExcel(dt);

            var filename = "StockOnHand.xlsx";
            var contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.Clear();
            Response.ContentType = contenttype;
            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(stream.ToArray());
            Response.End();
        }
        catch (Exception ex)
        {
            ErrorHandlerClass.LogMessage(ex.Message + ex.StackTrace);
        }
    }
</code></pre>

<p>Thanks In Advance</p>