Doing research inside a Session

Asked

Viewed 100 times

1

I have a role in controller that returns me one JSON, who picked up a JQuery and mount my page. I, store her return in a Session, as below:


SessaoUtil.SalvarSession("PegaHotelPacote", package.Buscar((SessaoUtil.Recuperar("sessionId") != null ? SessaoUtil.Recuperar("sessionId").ToString() : ""), tbSearch));

Now, after the generated result, I have some filters that I need to make work. I need now, to search in this Sesssion. Type: The result brought me 10 htéis, with their prices, qde rooms and etc... Well, I now want to search Hotel Melia, for example, through a textedit on my page. All this in jquery, people. How would I do that? I called this field txtNomeHotel, in accordance with HTML below: Everything is in one Jquery, I just picked up the field because otherwise would be extremely great the post of this forum.


<div class="select-group">;
     <input name="txtNomeHotel" placeholder="nome do hotel" />;
</div>;
  • thanks Eduardo. How do I put tags? Before it came automatic, but now how do I do?

1 answer

1

Create in your controller a method responsible for doing the research, and then call this method via ajax, and reconstruct the list of hotels with the items returned from the call:

Controller method:

public JsonResult FindHotel(string nome)
{
    var result = db.Hoteis.Where(x => x.Nome.Contains(nome)).ToList();
    return this.Json(result, JsonRequestBehavior.AllowGet);
}

Now just call this controller method via ajax like this:

$.ajax({
    type: 'GET',
    url: @Url.Action("FindHotel", "Controller"),
    processData: true,
    data: { nome: $("#txtNomeHotel").val() },
    success: function (listaHoteis) {
        for (var i = 0; listaHoteis.length; i++)
        {
            var hotelDados = listaHoteis[i];
            // recriar a lista de hoteis
        }
    }
});

And put an ID in your input:

<div class="select-group">;
     <input id="txtNomeHotel" name="txtNomeHotel" type="text" placeholder="nome do hotel" />;
</div>
  • A question. How do I exit the tab field to run the query?

  • I solved it. I put it in the text onblur and it worked. Thanks for the help. The post can be closed. I don’t know how to do it yet.

  • Just mark the answer as accepted. See the link to understand: How and why to accept an answer?

Browser other questions tagged

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