Pass parameters to PDF

Asked

Viewed 23 times

1

Hello Developers!

This is my Controller

    public ActionResult PrintList()
    {
        return View();
    }
    public ActionResult PdfJardimAtl()
    {
        var estrangeiros = db.Tb_estrangeiros_pe.Where(s => s.Tb_territorios.TerritorioName == "JARDIM ATLÂNTICO");

        return new Rotativa.ViewAsPdf(estrangeiros)
        {
            PageSize = Size.A4,
            PageOrientation = Orientation.Landscape
        };
    }

With this controller I have to type several commands for each territory. Also, I have to generate several Views. I have 20 territories. That way my controller will have to generate 20 Views

I would like to use parameter:

public ActionResult PdfJardimAtl(string territorio)
    {
        var estrangeiros = db.Tb_estrangeiros_pe.Where(s => s.Tb_territorios.TerritorioName == territorio);

        return new Rotativa.ViewAsPdf(estrangeiros)
        {
            PageSize = Size.A4,
            PageOrientation = Orientation.Landscape
        };
    }

That’s the View that I use to print the data in PDF

@model IEnumerable<mt2414_v6.Models.DataSet.Tb_estrangeiros_pe>

<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/ie10.css" rel="stylesheet" />
<link href="~/CustomThemes/structure-table-cx.css" rel="stylesheet" />
<link href="~/Content/bootstrap_edited.min.css" rel="stylesheet" />

<title>JARDIM ATLÂNTICO</title>

<table class="table-grey table-condensed">
    <tr class="table-secondary">
        <th scope="col" width="13%">@Html.DisplayNameFor(model => model.Nome)</th>
        <th scope="col" width="10%">@Html.DisplayNameFor(model => model.Tb_paises.PaisName)</th>
        <th scope="col" width="30%">@Html.DisplayNameFor(model => model.Endereco)</th>
        <th scope="col" width="7%">@Html.DisplayNameFor(model => model.Bairro)</th>
        <th scope="col" width="40%">@Html.DisplayNameFor(model => model.Obs)</th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>@Html.DisplayFor(modelItem => item.Nome)</td>
            <td>@Html.DisplayFor(modelItem => item.Tb_paises.PaisName)</td>
            <td>@Html.DisplayFor(modelItem => item.Endereco)</td>
            <td>@Html.DisplayFor(modelItem => item.Bairro)</td>
            <td>@Html.DisplayFor(modelItem => item.Obs)</td>
            <td></td>
        </tr>
    }

</table>

That is the result: inserir a descrição da imagem aqui

This is the main View that calls the PDF pages:

ViewBag.Title = "PrintList";
<h2>EXPORTAR LISTA PARA PDF</h2>
<li>@Html.ActionLink("CIDADE ALTA", "PdfCidadeAlt")</li>
<li>@Html.ActionLink("JARDIM ATLÂNTICO", "PdfJardimAtl")</li>
<li>@Html.ActionLink("PAULISTA", "PdfPaulista")</li>

It is possible with only one View i receive this parameter and generate the PDF pages?

  • Avoid putting pictures in your questions, just put the code so we can help you.

  • Sorry. Ready, I edited.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.