1
I’m in trouble to render some fields from my table in the file PDF. It was working fine, but I don’t know what happened to those fields are no longer rendering. On my screen My Courses, the pupil has a button that emits a Statement of Completion of Course, but when the student clicks on the button and generates the PDF the fields come data-free. Obs.: The data that should render in the PDF are: Student Name, Enrollment, Course Name, Period and Workload.
View PDF
@model MeuProjeto.Models.AlunoCurso
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/PDF.css" rel="stylesheet" type="text/css" />
<title>GeraPDF</title>
</head>
<body>
<br/> <br/>
<div id="declaracao">
<strong style="font-family: 'Times New Roman'">Declaração de Conclusão de Curso</strong>
</div>
<br/>
<hr/>
<text style="font-family: 'Times New Roman'; font-size: 20px">
Declaramos que o Sr(a). <b>@Html.DisplayFor(model => model.Aluno.Nome)</b>, matrícula de Nº <b>@Html.DisplayFor(model => model.Aluno.Matricula)</b>,
inscrito no curso de <b>@Html.DisplayFor(model => model.Curso.Nome_Curso)</b>, na XXXXX,
no período de <b>@Html.DisplayFor(model => model.Curso.Dt_Inicio)</b> a <b>@Html.DisplayFor(model => model.Curso.Dt_Fim)</b>,
cumprindo uma carga horária de <b>@Html.DisplayFor(model => model.Curso.Carga_Horaria)</b>, com total comprometimento e dedicação todos os requisitos para a conclusão deste curso,
estamos encaminhando esta via de Declaração para que seja emitido junta a XXXXXX, o
<b>Certificado</b> de conclusão de Curso.
</text>
<hr/>
<div id="assinatura">
_________________________ <span>em</span><span> ___/___/_____</span><br/>
Assinatura do Responsável
</div>
</body>
</html>
Action PDF
public ActionResult GerarPDF(int id)
{
var alunoCurso = db.AlunoCursos.FirstOrDefault(ac => ac.Aluno.Usuario == User.Identity.Name);
if (alunoCurso != null)
{
AlunoCurso aluno =
db.AlunoCursos.Include(a => a.Aluno).AsNoTracking().FirstOrDefault(al => al.AlunoId == id);
var pdf = new ViewAsPdf
{
ViewName = "GeraPDF",
FileName = "Declaração.pdf",
Model = aluno,
PageSize = Size.A4,
PageMargins = new Margins {Bottom = 2, Left = 2, Right = 2, Top = 2}
};
return pdf;
}
return View();
}
Snippet from my View with the Call PDF button
@model IEnumerable<MeuProjeto.Models.AlunoCurso>
<!-- Aqui é BOTÃO onde chama a página do PDF -->
<div class="btn-group">
<div class="col-md-offset-2 col-md-10">
@if (item.Aprovado == false)
{
<input type="submit" value="Pendente de Aprovação" name="meusCursos" class="cursos btn btn-primary btn-sm" disabled="disabled" data-id="@item.Id" />
}
else
{
<a href="~/AlunoCursos/[email protected]" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-print"></span></a>
}
</div>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(document).ready(function () {
$(".cursos").click(function () {
$.ajax({
type: "POST",
url: "MeusCursos/",
data: { id: $(this).data("id") },
success: function () {
$(this).attr("enable", "enable");
}
});
});
});
</script>
Ever tried to put breakpoints in View to check the status of the Model?
– Leonel Sanches da Silva
I put @Ciganomorrisonmendez, it’s not bringing anything. The funny thing is that it was working, and now I don’t know what happened. Can help me?
– Novato