1

Below I've added my full Index.cshtml code. In ajax call it's hitting to success method. but i'm not able to reload or refresh the table without page refresh.

The below code is simple while clicking the submit button for filters i'm calling SubmitFilter method it redirect to c# method there i'm storing the results in a JArray variable.. then trying to reload the table...

this is the sample output screen

enter image description here

I've tried these

$("#tblTransactions").DataTable().draw(); $("#tblTransactions").DataTable().ajax.reload();

But it's not working for me. please Let me know if you got any idea ..thanks in advance..

@page
@model IndexModel
@{
    Layout = "_Layout";
}
    
<script>
    $(document).ready(function () {
        $("#tblTransactions").DataTable();
   });
function SubmitFilter()
{

    var transactionNumb = $("#transactionNumber").val();
    var cardHolderName = $("#cardHolder").val();
    alert("SubmitFilter");
    $.ajax({
    type: "GET",
    url: "https://localhost:7197/Transactions?transaction_number="+transactionNumb+"&cardholder="+cardHolderName,
    contentType: "application/json; charset=utf-8",
    dataType: "html",
    success: function (data)
    {
      
    }
    });
}
</script>

 
       <a style="max-width: 100px;max-height: 40px;margin-left: 10px;" href="#" onclick="SubmitFilter();" class="btn btn-primary">SUBMIT</a>
  
    

<table id="tblTransactions" class="table table-bordered table-condensed table-striped table-hover">
    <thead>
        <th scope="col">Transaction No</th>
        <td scope="col">Type</td>
        <td scope="col">Status</td>
    </thead>
    <tbody>
    @foreach (dynamic transaction in @Model.Transactions)
    {

        <tr>
            <td>@transaction.transaction_number</td>
            <td>@transaction.type</td>
            <td>@transaction.status</td>
        </tr>
    }
    </tbody>
</table>
Vasanth R
  • 172
  • 1
  • 1
  • 14
  • You can follow this [question](https://stackoverflow.com/questions/12934144/how-to-reload-refresh-jquery-datatable). Hope you'll get your answer. – Md. Amin Hossain Jul 18 '22 at 12:16
  • For testing purposes, could you try to clear the data in your HTML table and then try to call code something like `var table = $('#example').DataTable(); table.ajax.reload( function ( json ) { $('#myInput').val( json.lastInput ); } );` Ref: [ajax.reload()](https://datatables.net/reference/api/ajax.reload()) – Deepak-MSFT Jul 19 '22 at 06:09

0 Answers0