Ramco Ramco

Ramco Ramco

  • 469
  • 2.8k
  • 394k

Refresh DataTable after Add

Jun 2 2021 10:19 AM
Hi
 
I have below controller & JS. I want to refresh datatable after Add & display message in popup
  1. <table table table-striped table-bordered" style="width:100%" id="tblLocation">  
  2. <thead>  
  3. <tr>  
  4. <th>  
  5. @Html.DisplayNameFor(model => model.Id)  
  6. </th>  
  7. <th>  
  8. @Html.DisplayNameFor(model => model.Description)  
  9. </th>  
  10. <th>  
  11. @Html.DisplayNameFor(model => model.IsActive)  
  12. </th>  
  13. <th>Action</th>  
  14. </tr>  
  15. </thead>  
  16. <tbody>  
  17. @foreach (var item in Model)  
  18. {  
  19. <tr [email protected]>  
  20. <td>  
  21. @Html.DisplayFor(modelItem => item.Id)  
  22. </td>  
  23. <td>  
  24. @Html.DisplayFor(modelItem => item.Description)  
  25. </td>  
  26. <td>  
  27. @Html.DisplayFor(modelItem => item.IsActive)  
  28. </td>  
  29. <td>  
  30. <a class='btn btn-primary btn-sm' id='btnEdit'><i class='fa fa-pencil'></i> Edit</a>  
  31. <a class='btn btn-danger btn-sm' id='btnDelete' style='margin-left:5px'  
  32. @{ if(item.IsActive == "N")  
  33. {  
  34. @:disabled="disabled"  
  35. }  
  36. }><i class='fa fa-trash'></i> Delete</a>  
  37. </td>  
  38. </tr>  
  39. }  
  40. </tbody>  
  41. </table>  
  1. function Add() {  
  2. var res = validate();  
  3. if (res == false) {  
  4. return false;  
  5. }  
  6. var objLocation = {  
  7. Id: $('#txtId').val().toUpperCase(),  
  8. Description: $('#txtDescription').val().toUpperCase(),  
  9. IsActive: $('#txtIsActive').val().toUpperCase()  
  10. };  
  11. $.ajax({  
  12. url: "/Location/Add",  
  13. data: JSON.stringify(objLocation),  
  14. type: "POST",  
  15. contentType: "application/json;charset=utf-8",  
  16. dataType: "json",  
  17. success: function () {  
  18. $.notify(result.message, {  
  19. globalposition: "top center",  
  20. //position:"center",  
  21. className:"success"  
  22. })  
  23. $('#myModal').modal('hide');  
  24. },  
  25. error: function (xhr, ajaxOptions, thrownError) {  
  26. $("#msgModalBody").html('Status : ' + xhr.status + ' Error : ' + thrownError);  
  27. $("#msgModal").modal('show');  
  28. }  
  29. });  
  30. }  
Thanks

Answers (3)