I'm trying to use RazorPDF2 to generate the PDF of a view . I put a breakpoint in both the controller and the view and both are running without any error, however after finishing execution always returns the error: / p>
The document has no pages.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The document has no pages.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information about the origin and location of the exception can be identified using the exception stack trace below.
Follow my controller:
public ActionResult Pdf(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Orcamentos Orcamentos = db.Orcamento.Find(id);
var pdf = new PdfActionResult( Orcamentos);
pdf.FileDownloadName = "Pdf";
pdf.ViewName = "Pdf";
return pdf;// View(Orcamentos);
}
Follow the View (I only left the basics, but it will not go away anyway):
@model OrcamentosSeal.Models.Orcamentos
@{
ViewBag.Title = "Orcamento" + Model.Orcamento.CJ_NUM;
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
</head>
<body>
<p>Teste</p>
</body>
</html>
I reinstalled the package via NugGet and used the _PdfHtmlLayout.cshtml and it worked.