How to download data from a sql table as pdf file in asp.net mvc?
I made excel, but the pdf was not available. I also sent you the excel code, you can look at it too.
public void GridExportToExcel()
{
var ad = (string)Session["FIRMAKODU"];
string dosyaAdi = "Cariler";
var table = db.WEBCARI.Where(x => x.FIRMAKODU == ad).ToList();
var grid = new GridView();
grid.DataSource = table;
grid.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + dosyaAdi + ".xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
<a href="#" id="export" class="btn btn-outline-warning">Excel</a>
<script>
$(document).ready(function () {
$("#export").click(function () {
ExportToExcel();
});
});
function ExportToExcel()
{
var url = '@Url.Action("GridExportToExcel", "Cari")';
window.open(url);
}
</script>