1

我正在使用 MVC 4 并使用 rotativa PDF 从视图中生成 pdf。问题是有问题的视图是 LINQ 搜索的结果,并且在 pdf 中它没有出现数据。

这是用户用他想要搜索的内容填充框的地方:

第一的

在他单击“Pesquisar”(搜索)后,将创建此视图:

第二

但是当生成pdf时,它不显示任何数据。

我能做什么或错误是什么?编码:

控制器(LINQ 代码有效):

    public ActionResult ViewAfterSearch(string texto)
    {

        var util = (db.Simulacaos.Where(m =>
            m.Utilizador.Contains(texto)));

        return View("ViewAfterSearch", util);
    }

    public ActionResult ViewBeforeSearch()
    {
        return View(db.Simulacaos.ToList());
    }

    [HttpPost, ActionName("ViewBeforeSearch")]
    public ActionResult ViewBeforeSearch(string texto)
    {
        var util = (db.Simulacaos.Where(m =>
            m.Utilizador.Contains(texto)));
        return View("ViewAfterSearch", util);
    }

意见:

    @model IEnumerable<GestorSalas.Models.Simulacao>

@{
    ViewBag.Title = "Registos";
}

<h2>ViewAfterSearch</h2>

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Utilizador)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TipoUtilizador)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Codigo)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Hora)
        </th>
        <th>
            Entrou?
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Utilizador)
            </td>
            <th>
                @Html.DisplayFor(modelItem => item.TipoUtilizador)
            </th>
            <td>
                @Html.DisplayFor(modelItem => item.Codigo)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Hora)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Entrar)
            </td>
        </tr>
    }

</table>

<h4>@Html.ActionLink("Download como PDF", "TurnToPDF", "Simulacao")</h4>
<h4>@Html.ActionLink("Voltar", "Index", "Simulacao")</h4>

搜索前查看:

@model IEnumerable<GestorSalas.Models.Simulacao>

@{
    ViewBag.Title = "Index";
}
    <h4>Procurar registo de utilizadores</h4>  

    using (Html.BeginForm("ViewAfterSearch", "Simulacao", FormMethod.Post))
{
<table>
    <tr>
        <th>
            @Html.TextBox("texto")
        </th>
        <td>
            <input type="submit" id="ButtonProcura" value="Procurar" />
        </td>
    </tr>
</table>
}

    @Html.ActionLink("Download como PDF", "TurnToPDF", "Simulacao")

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Utilizador)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TipoUtilizador)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Codigo)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Hora)
        </th>
        <th>
            Entrou?
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Utilizador)
        </td>
        <th>
            @Html.DisplayFor(modelItem => item.TipoUtilizador)
        </th>
        <td>
            @Html.DisplayFor(modelItem => item.Codigo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Hora)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Entrar)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.SimulacaoId }) |
            @Html.ActionLink("Details", "Details", new { id=item.SimulacaoId }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.SimulacaoId })
        </td>
    </tr>
}

</table>
}
4

0 回答 0