Search within a session

1

I have a function in controller that returns me a JSON , which I get in a JQuery and I 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 to now, search this session. Type: The result has brought me 10 htéis, with its prices, qde rooms and etc ... Well, I now search the Hotel Melia, for example, through a textedit on my page. All of this in jquery, folks. How would I do that? I called this field of txtNomeHotel , as HTML below: Everything is in a Jquery , I just took the field, otherwise it would be extremely great the post of this forum.

<div class="select-group">;
     <input name="txtNomeHotel" placeholder="nome do hotel" />;
</div>;
    
asked by anonymous 28.03.2014 / 16:18

1 answer

1

Create in your controller a method responsible for doing the search, and then call this method via ajax, and rebuild 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 method of the controller 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>
    
28.03.2014 / 17:45