Skip to content
Loading
Update Record .  
  •   
  • class="modal-footer">  
  • "button" class="btn btn-outline-dark" data-dismiss="modal">Cancel  
  • "button" class="btn btn-primary" id="btnAdd" onclick="return Add();">class="glyphicon glyphicon-ok">Save Changes  
  • "button" class="btn btn-primary" id="btnUpdate" style="display:none;" onclick="Update();">Update  
  •   
  •   
  •   
  •   
    1. $(document).ready(function () {  
    2. $("#tblLocation").dataTable({  
    3. ajax: {  
    4. type: "get",  
    5. url: "/Location/List",  
    6. dataType: "json",  
    7. dataSrc: ""  
    8. },  
    9. paging: true,  
    10. sort: true,  
    11. pageLength: 5,  
    12. searching: true,  
    13. columns: [  
    14. { 'data': 'Id' },  
    15. { 'data': 'Description' },  
    16. {  
    17. //"data": null,  
    18. "defaultContent": ''  
    19. }  
    20. ]  
    21. });  
    22. $('body').on('click', '[id*=btnEdit]', function () {  
    23. var data = $(this).parents('tr').find('td');  
    24. var id = data.eq(0).html();  
    25. var description = data.eq(1).html();  
    26. $('[id*=txtId]').val(id);  
    27. $('[id*=txtDescription]').val(description);  
    28. $('#myModal').modal("show");  
    29. });  
    30. });  
    31. function Update() {  
    32. var res = validate();  
    33. if (res == false) {  
    34. return false;  
    35. }  
    36. var objLocation = {  
    37. Id: $('#txtId').val().toUpperCase(),  
    38. Description: $('#txtDescription').val().toUpperCase()  
    39. };  
    40. $.ajax({  
    41. url: "/Location/Update",  
    42. data: JSON.stringify(objLocation),  
    43. type: "POST",  
    44. contentType: "application/json;charset=utf-8",  
    45. dataType: "json",  
    46. success: function (result) {  
    47. $('#tblLocation').DataTable().ajax.reload();  
    48. $('#myModal').modal('hide');  
    49. clearTextBox();  
    50. },  
    51. error: function (errormessage) {  
    52. alert(errormessage.responseText);  
    53. }  
    54. });  
    55. }  
    Thanks

    1 Reply

    Know the answer? Post it — somebody with the same question will find it here.