I'm using Rotativa to generate a PDF file from a view, which works well, but now on the browser I get the raw file thrown at the console, no download dialog box, no warning, nothing. Here's my code:
Controller
public ActionResult DescargarPDF (int itemId) {
var presupuesto = ReglasNegocio.Fachada.Consultas.ObtenerPresupuesto(itemId);
return new Rotativa.PartialViewAsPdf("_PresupuestoFinal", presupuesto) {
FileName = "Presupuesto_" + itemId + ".pdf",
PageSize = Rotativa.Options.Size.A4
};
}
JQuery script:
$(".convertirPDF").on("click", function (id) {
var itemId = $(this).data('itemid');
Pdf(itemId);
});
function Pdf(itemid) {
var id = itemid;
$.ajax({
method: "POST",
url: 'DescargarPDF',
data: { itemId: id },
cache: false,
async: true,
});
};
Button on the HTML
<button class="convertirPDF btn btn-secondary btn-info" data-itemid="@item.Id">PDF</button>
I've tried several codes on the controller (with same result) since the script and view seems to work fine. However, I'm suspecting, maybe the html or the script need some tuning to inform the browser it has to download the file?
Thanks everyone in advance.