0
I want to show a message on the screen instead of showing an empty table. How do I implement this logic in index.cshtml?
@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>
Make an if (Model.Service?.Length > 0) around your table and put in ELSE what you want to show.
– Bruno Warmling