filter table Asp.net mvc

Asked

Viewed 637 times

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?

  • 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

  • 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?

  • Then, it returns the right, filtered list. Only it is not showing on the screen the filter result

  • In the browser console (F12) some error appears?

  • 1

    in ajax is missing an "s" in succes. has to be success

  • I can’t believe it was an "s," thank you guys. I was already depressed that I couldn’t do it. hahahaha

Show 2 more comments

1 answer

3

Putting as answer to help anyone who has the same problem. (or who is too lazy to read comments)

Error happens due to a typo in the function success of $.ajax:

function Buscar() {
     $.ajax({
            url: '@Url.Content("~/Home/RetornaCorp")',
            type: 'POST',
            data:
            {
                produto: $("#Produto").val()
            },
            success: function (data) { //Coreção aqui, adicionando um "S"
                $("#partial").html(data);
            }
     });
}

Browser other questions tagged

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