Show information when there is no data

-2

I made a if , if something comes back, then it mounts a page, otherwise it should hide everything and display a message. Not an alert, but a message on the page itself. In my else I just hide a div and a form. This is okay. Just do not know how to generate a message, type a <h1>Mensagem</h1> , type this, not necessarily this, but something like that. See my else as is:

else
{
     $("#selecionarHotel").css("display","none");
     $("#filtroPesquisa").prop("hidden", true);
}
    
asked by anonymous 02.04.2014 / 22:29

2 answers

3

In Razor, you can do the following in your View :

@if (Model.Count > 0) {
    // Seu código
} else {
    <div>Não há registros a serem exibidos.</div>
}

For this to be feasible you must have a Model applied to your view. For example:

@model IEnumerable<Caminho.Da.Minha.Classe>
    
02.04.2014 / 22:43
2

I imagine the data is arriving at its View asynchronously. In this case, you can have a html structure ready to display this message and keep it in a css class that hides. If your Model is empty, you can implement a javascript routine to display it, here's an example:

in your css

.no-data {
   display: none;
}

In your html, you could keep a div with your message by applying css that hides:

<div id="mensagem" class="no-data">Nenhuma registro encontrado.</div>

and to display, in your javascript:

$("#mensagem").show();

If the data in your View sees directly in Model , so you can implement this routine on the server side to generate the html, eg:

@if (Model.Count > 0) 
{
    // sua exibição aqui...
} 
else 
{
    <div>Nenhuma registro encontrado.</div>
}
    
02.04.2014 / 22:45