0
I need to filter a table, which is in a partial view, depending on the parameter typed in a field, which is passed to the controller via ajax. How to reload the table with the filter applied?
Part of the index where my partial
<div class="row" id="partial">
@{Html.RenderPartial("Partial_table", Model);}
</div>
Partial view, where the table is loaded
@model IEnumerable<OAP.Web.MVC.Corp.Models.CorpCRM>
<div style="overflow: auto; height: 700px">
<table id="tbEstatica" class="myTable">
<tr class="myTable">
<th class="myTable">Data</th>
<th class="myTable">Matricula</th>
<th class="myTable">Produto</th>
<th class="myTable">Contrato</th>
<th class="myTable">Penumber</th>
<th class="myTable">Nome Cliente</th>
<th class="myTable">Valor</th>
<th class="myTable">Agencia / Conta</th>
</tr>
<tbody>
@{
foreach (var item in Model)
{
<tr style="height: 50px" class="myTable">
<td class="myTable">@item.Dt_Contab</td>
<td class="myTable">@item.Matricula</td>
<td class="myTable">@item.Produto</td>
<td class="myTable">@item.Contrato</td>
<td class="myTable">@item.Penumber</td>
<td class="myTable">@item.Nome_Cliente</td>
<td class="myTable">@item.Valor</td>
<td class="myTable">@item.Agencia_Conta</td>
</tr>
}
}
</tbody>
</table>
Ajax passing the field parameter;
<script>
function Buscar() {
$.ajax({
url: '@Url.Content("~/Home/RetornaCorp")',
type: 'POST',
data:
{
produto: $("#Produto").val()
},
succes: function (data) {
$("#partial").html(data);
}
});
}
Controller that receives the Ajax parameter
public ActionResult RetornaCorp(int Produto)
{
CorpDAO dao = new CorpDAO();
listaCRM = dao.ListarCorp(Produto);
return PartialView("Partial_table", listaCRM);
}
I don’t think I understand. You’re already filtering the data, no?
– Randrade
When I click the button to make this flow, the parameter arrives in the controller but does not filter the table. I don’t know if I’m doing something wrong
– Paulo Henrique
Post your method
ListarCorp(produto)
. You know debug your code to see if you are passing the correct values? There is an error in the console (F12) by clicking the button?– Randrade
Then, it returns the right, filtered list. Only it is not showing on the screen the filter result
– Paulo Henrique
In the browser console (F12) some error appears?
– Randrade
in ajax is missing an "s" in
succes
. has to besuccess
– Marllon Nasser
I can’t believe it was an "s," thank you guys. I was already depressed that I couldn’t do it. hahahaha
– Paulo Henrique