c# - how to return pdf file result to ajax jquery and display it in new tab of browser -


i want generate pdf using rdlc. want call using ajax, returns correct data dont know how show in browser.

public class customercontroller  {  //render report  public fileresult printpofile(customerinputmodel model)     {         //file generation logic          renderedbytes = localreport.render(             reporttype,             deviceinfo,             out mimetype,             out encoding,             out filenameextension,             out streams,             out warnings);          //filestream fs = new filestream(filepath, filemode.create);         using (filestream fs = new filestream(server.mappath("~/download/") + filename + ".pdf", filemode.create))         {             fs.write(renderedbytes, 0, renderedbytes.length);         }          response.clearheaders();         response.clearcontent();         response.buffer = true;         response.clear();         response.contenttype = "application/pdf";         response.addheader("content-disposition", "inline; filename=" + filename + ".pdf;");          response.writefile(server.mappath("~/download/" + filename + ".pdf"));         response.flush();         response.close();         response.end();          string pdfurl = server.mappath("~/download/" + filename + ".pdf");   return file(pdfurl, "application/pdf");     }   [httppost]     public actionresult printfile(string id)     {         int id = convert.toint32(id);                     customerinputmodel customerprintmodel = getcustomer(id);           //function information of customer         printpofile(customerprintmodel );         return view(customerprintmodel );     } 

but when call function ajax on button click,

  <p>                 <input type="button" value="print po" id="printbtn" name="button" />             </p>  $("#printbtn").click(function (){  var id = $("#id").val();      $.ajax({             url: "/customer/printfile",             type: "post",             data: {id : id},             success: function (data)              {                 alert(data);                                          window.open("http://localhost:51035/download/"+data,"_blank");               }         });       //  alert("print");     }); </script> 

alert(data); shows unicode characters want pdf file open in new tab of browser. want on button click when click button, should go url specified in ajax, on action called function returns file.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -