asp.net mvc - MVC - How to download a csv file using ajax in mvc3 -


i have problem in downloading csv file using $.ajax(); code.

i have controller returning file below.

public actionresult exportex() {    stringbuilder sb = new stringbuilder();         sb.append("<table>");                     sb.append("<tr>");         sb.append("<td>1</td>");         sb.append("<td>2</td>");         sb.append("<td>3</td>");         sb.append("<td>4</td>");         sb.append("</tr>");         sb.append("<table>");               httpcontext.response.addheader("content-disposition", "attachment; filename=student_" + datetime.now.year.tostring() + ".xls");     this.response.contenttype = "application/vnd.ms-excel";     byte[] buffer = system.text.encoding.utf8.getbytes(sb.tostring());     return file(buffer, "application/vnd.ms-excel"); } 

i have index.cshtml file below

<input type="submit" value="export excel" title="export excel" />          <script type="text/javascript">     $(".tt").click(function () {         $.ajax({             url: '/home/exportex',             type: 'post',             data: {},             success: function (data) { },             complete: function (data) { }         });     }); </script> 

if call using <a class="tt" href="@url.action("exportex", new { })">export</a> can download csv file. through $.ajax call can not download.

kindly me in this.

thanks in advance.

        $('button').click(function () {             window.location.href = '/home/exportex';         }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -