Show information when no data

Asked

Viewed 183 times

-2

I made a if, in case something comes back, then he mounts a page, otherwise he should hide everything and show a message. It’s not an Alert, but a message on the same page. On my Lse I just hide a div and a form. That’s okay. I just don’t know how to generate a message, like a <h1>Mensagem</h1>, like that, not necessarily that, but something like that. Look at my else how are:

else
{
     $("#selecionarHotel").css("display","none");
     $("#filtroPesquisa").prop("hidden", true);
}

2 answers

3

On Razor, you can do the following on your View:

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

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

@model IEnumerable<Caminho.Da.Minha.Classe>
  • I can’t get the Model Count. He doesn’t exist.

  • You can put in the question the complete code of your View?

  • the view is very large, but I can place the Model object that my view loads.

  • Could be just the header of View. I need to know how you send the information to View to edit my reply.

  • 3

    @pnet guy, you need to get used to using SOPT as it should be... People are complaining a lot about your use of the site because you don’t choose the answers that solve your problem, or provide questions with enough subsidies. Help us maintain the high level of this community

  • If you set a @Model as IEnumerable, Count has exist

Show 1 more comment

2

I imagine the data is coming in your View asynchronously. In this case, you can have a html ready to display that message and keep it in a class css that hides. Your case Model come empty, you can implement a routine javascript to display it, let’s take an example:

in his css

.no-data {
   display: none;
}

in your html, you could keep a div with your message applying the 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 see directly into the Model, so you can implement this server-side routine to generate html, example:

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

Browser other questions tagged

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