How to show a message on the screen, if there are no records to be brought from the database?

I want to show a message on the screen instead of showing an empty table. How do I implement this logic in index.cshtml?

insert the description of the image here

@page
@model xxx.xxx.Pages.Servicos.IndexModel

@{
    ViewData["Title"] = "Serviços";
}

<h2>Serviços</h2>

<p>
    @{
        if (await Model.PermiteIncluirAsync())
        {
            <a asp-page="Create">Novo serviço</a>
        }
    }
</p>

<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].Descricao)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].UnidadeDeMedida)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].Grupo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].Subgrupo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].ValorUnitario)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].CargoResponsavel)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Servicos[0].Observacoes)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
    @foreach (var item in Model.Servicos) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Descricao)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.UnidadeDeMedida)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Grupo)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Subgrupo)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ValorUnitario)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CargoResponsavel)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Observacoes)
            </td>
            <td>
                @{
                    if (await Model.PermiteAlterarAsync())
                    {
                        <a class="btn btn-default" asp-page="./Edit" asp-route-id="@item.Id">Editar</a>
                    }

                    if (await Model.PermiteVisualizarAsync())
                    {
                        <a class="btn btn-default" asp-page="./Details" asp-route-id="@item.Id">Detalhes</a>
                    }

                    if (await Model.PermiteExcluirAsync())
                    {
                        <a class="btn btn-default" asp-page="./Delete" asp-route-id="@item.Id">Excluir</a>
                    }
                }
            </td>
        </tr>
    }
    </tbody>
</table>

Author: Victor Moraes, 2019-11-20

1 answers

You can use if to check the number of records:

@if (model.Servicos.Count == 0)
{
   // mensagem que você quer
}
else
{
   // o código com resgistro
}   
 1
Author: Rafa C., 2019-11-20 14:04:10