Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpGet]
- public JsonResult Eliminar(int id = 0)
- {
- try
- {
- Empleado empleado = empleados.Where(x => x.Id == id).FirstOrDefault();
- empleados.Remove(empleado);
- return Json(empleados, JsonRequestBehavior.AllowGet);
- }
- catch (Exception ex)
- {
- return Json(false);
- }
- }
- @section Scripts{
- <script type="text/javascript">
- $('.eliminar').click(function () {
- var idEliminar = $(this).attr("data-id");
- $("#btnEliminar").attr("data-eliminar", idEliminar);
- $("#myModal").modal();
- });
- $("#btnEliminar").click(function () {
- var idEliminar = $(this).attr("data-eliminar");
- $.ajax({
- url: '/Empleado/Eliminar',
- type: 'get',
- data: { id: idEliminar },
- dataType: 'json',
- success: function (result) {
- console.log("Exito");
- $("#" + idEliminar).remove();
- $("#myModal").modal('hide');
- },
- error: function () {
- console.log("fallo");
- }
- });
- });
- </script>
- }
- public class Result
- {
- public string _result, _message, _URL;
- public object _body;
- public int? _cant;
- }
- [HttpGet]
- public JsonResult Eliminar(int id = 0)
- {
- Result datos = null;
- try
- {
- Empleado empleado = empleados.Where(x => x.Id == id).FirstOrDefault();
- empleados.Remove(empleado);
- datos.message = "success";
- datos.result_ = "success";
- datos.cant = 1;
- }
- catch (Exception ex)
- {
- datos.message = ex.Message;
- datos.result_ = "error";
- }
- return Json(datos);
- }
- @section Scripts{
- <script type="text/javascript">
- $('.eliminar').click(function () {
- var idEliminar = $(this).attr("data-id");
- $("#btnEliminar").attr("data-eliminar", idEliminar);
- $("#myModal").modal();
- });
- $("#btnEliminar").click(function () {
- var idEliminar = $(this).attr("data-eliminar");
- $.ajax({
- url: '/Empleado/Eliminar',
- type: 'get',
- data: { id: idEliminar },
- dataType: 'json',
- contentType: "application/json;charset=utf-8",
- success: function (result) {
- if(result.result_ == 'success'){
- console.log("Exito");
- $("#" + idEliminar).remove();
- $("#myModal").modal('hide');
- }else{
- console.log("error", result.message);
- }
- },
- error: function (err) {
- console.log(err);
- }
- });
- });
- </script>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement