function Deleterep(cusid) {
var res = confirm('You want to delete this Customer??');
if (res) {
$.ajax({
type: "POST",
url: "/Customer/Deletere",
dataType: "html",
data: { cusid: cusid },
success: function (data) {
$("#table-content").html(data);
}, error: function (xhr, err) {
alert("Error occured, Please try again.");
}
});
}
}
public ContentResult Deletere(int cusid)
{
string message = "Cannot delete"; // replace with your own message
BayDiamondEntities db = new BayDiamondEntities();
int count = db.t_Repair.Where(o => o.CustomerID == cusid).Count();
if (count == 0)
{
t_Customer customer = db.t_Customer.Where(c => c.Id == cusid).SingleOrDefault();
if (customer != null)
{
db.t_Customer.Remove(customer);
db.SaveChanges();
message = "Done";
}
}
return Content(message);
}
function Deleterep(cusid) {
var res = confirm('You want to delete this Customer??');
if (res) {
$.ajax({
type: "POST",
url: "/Customer/Deletere",
dataType: "html",
data: { cusid: cusid },
success: function (data) {
if (data == "1") {
alert("Deleted");
window.location = "/Customer/index";
}
alert("You can not delete");
}, error: function (xhr, err) {
alert("Error occured, Please try again.");
}
});
}
}
public ActionResult Deletere(int cusid)
{
BayDiamondEntities db = new BayDiamondEntities();
int count = db.t_Repair.Where(o => o.CustomerID == cusid).Count();
if (count == 0)
{
t_Customer customer = db.t_Customer.Where(c => c.Id == cusid).SingleOrDefault();
if (customer != null)
{
db.t_Customer.Remove(customer);
db.SaveChanges();
}
return Content("1");
}
else
return Content("0");
}
Html:
Open in new window
Open in new window
Now I need to know how to return from the controller.
please help.