MVC DELETE CONFIRMATION

Razer View:
@{
ViewBag.Title = “Home Page”;
}

.dialog_css
{
border: 0px none !important;
-moz-box-shadow: 1px 2px 4px 2px rgb(136, 136, 136);
-webkit-box-shadow: 1px 2px 4px 2px rgb(136, 136, 136);
box-shadow: 3px 6px 8px rgb(136, 136, 136);
}

Item Name Delete
Laptop Delete
Mobile Delete
ipad Delete

@section Scripts {
@Scripts.Render(“~/bundles/jqueryval”)

http://@Url.Content(
http://@Url.Content(

// delete Link
$(‘.delete-link’).click(function () {
var deleteLinkObj = $(this); //for future use

$(“#delete-dialog”).dialog({
title: “Confirmation”,
buttons: {
Continue: function () {
$.post(deleteLinkObj[0].href, function (data) { //Post to action
if (data.Status == ‘true’) {
var tr = deleteLinkObj.parents(‘tr:first’);
tr.hide(‘fast’); //Hide Row
}
else {
//(optional) Display Error
}
});
$(this).dialog(‘close’);
},
Close: function () {
$(this).dialog(‘close’);
}
},
dialogClass: ‘dialog_css’,
width: 400,
closeOnEscape: false,
draggable: false,
resizable: false,
modal: true
});
return false; // prevents the default behaviour

});

}

Controller:
[HttpPost]
public ActionResult Delete(int id)
{
try
{
return Json(new { Status = “true” });
}
catch
{
return Json(new { Status = “false” });
}
}

Leave a comment