Hi
How to refresh Datatable when record gets saved . I also want to display Notification message.
public JsonResult Add(Location objLocation) { if (ModelState.IsValid) { dbLocation.Add(objLocation); return Json(new { success = true, message = "Successfully Saved" }); } else { var query = from state in ModelState.Values from error in state.Errors select error.ErrorMessage; var errors = query.ToArray(); } return Json(objLocation); }
**************************************************************
@foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Id) </td> <td> @Html.DisplayFor(modelItem => item.Description) </td> <td> @Html.DisplayFor(modelItem => item.IsActive) </td> <td> <a class='btn btn-primary btn-sm' id='btnEdit' data-target="#myModal" data-toggle="modal"><i class='fa fa-pencil'></i> Edit </a>
@if (item.IsActive) { <a id="btnDelete" class="btn btn-danger btn-sm" data-target="#DeleteModal" data-toggle="modal" data-path="@Url.Action("Delete", "Location", new { id = @item.Id })" style='margin-left:5px'><i class='fa fa-trash'></i> Delete </a> } else { <a class='btn btn-danger btn-sm disabled' id='btnDelete' style='margin-left:5px'><i class='fa fa-trash'></i> Delete </a> } </td> </tr> }
***************************************
function Add() { var res = validate(); if (res == false) { return false; }
var objLocation = { Id: $('#txtId').val().toUpperCase(), Description: $('#txtDescription').val().toUpperCase(), }; $.ajax({ url: "/Location/Add", data: JSON.stringify(objLocation), type: "POST", contentType: "application/json;charset=utf-8", dataType: "json", success: function (data) { alert(data); $.notify(data.message, { globalposition: "top center", className: "success" }) $('#myModal').modal('hide'); }, error: function (xhr, ajaxOptions, thrownError) { alert("Error"); $("#msgModalBody").html('Status : ' + xhr.status + ' Error : ' + thrownError); $("#msgModal").modal('show'); // } }); }
Thanks