Estou tentando utilizar o RazorPDF2 para gerar o PDF de uma view. Coloco um breakpoint tanto no controller quanto na view e ambos estão executando sem erro algum, porém depois que termina a execução sempre retorna o erro:
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 regarding the origin and location of the exception can be identified using the exception stack trace below.
Segue meu 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);
}
Segue a View (deixei só o básico, mas mesmo assim não vai):
@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>
Reinstalei o pacote via NugGet e usei o modelo _PdfHtmlLayout.cshtml e funcionou.