0
Good afternoon, you guys!
Following scenario:
I have a search button in my Layout that uses the text field and select to send data to javascript, which calls an action, which calls the repository method to bring the data I need.
Everything works, data is returned, but the View is not displayed.
Action has the same name as the View that receives a List.
Call button:
<div class="col-lg-2 col-sm-2 col-md-2">
<input type="button" id="btnPesquisar" name="name" value="Pesquisar" />
@*<a href="#"> <span class="glyphicon glyphicon-search" onclick="javascript:FiltrarImovel();" /></a>*@
</div>
Action:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public ActionResult filtrarImovel(string texto, string filtro)
{
List<ImovelFiltradoViewModel> model = new List<ImovelFiltradoViewModel>();
model = repositorio.FiltrarImovel(texto, filtro);
model.OrderBy(i => i.ID_IMOVEL);
TempData["ImovelFiltrado"] = model;
return View(model.ToList());
}
View:
@model List<MeuImovel.Domain.ViewModel.ImovelFiltradoViewModel>
<h2>Imóveis</h2>
<hr />
<div class="container">
<div class="images">
@{foreach (var item in Model)
{
<div onclick="modal(@item.ID_IMOVEL, '@item.ENDERECO')">
<div class="item-content">
@if (item.fotos.Count > 0)
{
<img src="~/uploadeimg/@item.fotos[0].NomeAquivo" />
}
else
{
<img src="~/Content/Imagens/sem_foto_icone.jpg" />
}
<div class="item-options">
<div>
<div class="address">@item.ENDERECO</div>
<div class="price large-text">[email protected]("{0:n0}", item.VALOR_ALUGUEL)</div>
<div class="agent">
<div id="@("Imóvel" + item.ID_IMOVEL)">
<img src="~/Content/Imagens/iconetelefone.png">
Ligue Já
</div>
</div>
</div>
</div>
</div>
</div>
}
}
</div>
</div>
@section Scripts {
<link href="~/Content/RepeaterImoveis.css" rel="stylesheet" />
<script src="~/Scripts/Site.js"></script>
}
Javascript:
$(document).ready(function () {
$("#btnPesquisar").click(function () {
var campoTexto = document.getElementById("textoFiltroHome").value;
var campoLista = document.getElementById("dropFiltroHome").value;
//alert(campoTexto + " - " + campoLista);
$.ajax({
type: "POST",
cache: false,
url: 'Imoveis/filtrarImovel',
data: {texto: campoTexto, filtro: campoLista },
dataType: "json",
success: function (data) { ExecutarSucesso(data.d); },
error: function (data) { ExecutarErro(data.d); }
})
function ExecutarSucesso(result) { };
function ExecutarErro(result) { };
});
});