En iyi yanıtlayıcılar
RedirectToAction kullanma

Soru
-
public JsonResult Sil(int ID)
{
Sepetim sepet = db.Sepetim.Find(ID);
db.Sepetim.Remove(sepet);
db.SaveChanges();
int id = Convert.ToInt32(Session["KullaniciID"]);
int sepette_kalan = db.Sepetim.Where(x => x.Kullanici_ID == id).Count();
if (sepette_kalan == 0)
{//BURDA BAŞKA BİR ACTİON CALIŞTIRMAK VE YENİ BİR VİEW OLUŞTURMAK İSTİYORUM
return Json(new JsonResultModel { IsSuccess = true, UserMessage = "Ürün Sepetinizden kaldırıldı. Sepetiniz boş" });
}
return Json(new JsonResultModel { IsSuccess = true, UserMessage = "Ürün Sepetinizden kaldırıldı" });
}-------------------------------
$(document).on("click", '#SepetimDelete', function () {
var gelenID = $(this).attr("data-id");
var silTR = $(this).closest("tr");
$.ajax({
url: '/Sepetim/Sil/' + gelenID,
type: "POST",
dataType:'json',
success: function (response) {
silTR.fadeOut(300, function () {
$.notify(response.UserMessage, "success");
silTR.remove();
})
}
})
})ajax ile sil metodunu cağırıyorum. sepetteki son kayıtda silindikten sonra sepet_bos diye br actionresult çalıştırmak istiyorum bunu nasıl yaparım TEŞEKKÜR EDERİM.
Yanıtlar
-
yukarıdaki gibi yapamazsınız. Ayrıca JsonResultModel e de pek ihtiyaç yok gibi duruyor, şöyle yapabilirsiniz;
public JsonResult Sil(int ID) { Sepetim sepet = db.Sepetim.Find(ID); db.Sepetim.Remove(sepet); db.SaveChanges(); int id = Convert.ToInt32(Session["KullaniciID"]); int sepette_kalan = db.Sepetim.Where(x => x.Kullanici_ID == id).Count(); return Json(new { IsSuccess = true, UserMessage = "Ürün Sepetinizden kaldırıldı", Remain = sepette_kalan }); } ------------------------------- $(document).on("click", '#SepetimDelete', function () { var gelenID = $(this).attr("data-id"); var silTR = $(this).closest("tr"); $.getJSON('/Sepetim/Sil/' + gelenID) .success(function (response) { silTR.fadeOut(300, function () { $.notify(response.UserMessage, "success"); silTR.remove(); if(response.Remain <= 0) { alert('sepet boşaldı'); //ya da actiona gidin; location = 'Sepetim/SepetBos'; } }); }); })
e-mail: onay[nokta]yalciner[at]hotmail[nokta]com
- Yanıt Olarak Öneren Berkayaylaci 30 Haziran 2016 Perşembe 23:30
- Yanıt Olarak İşaretleyen Kyamuran SalibryamMicrosoft contingent staff, Moderator 13 Temmuz 2016 Çarşamba 22:12
Tüm Yanıtlar
-
yukarıdaki gibi yapamazsınız. Ayrıca JsonResultModel e de pek ihtiyaç yok gibi duruyor, şöyle yapabilirsiniz;
public JsonResult Sil(int ID) { Sepetim sepet = db.Sepetim.Find(ID); db.Sepetim.Remove(sepet); db.SaveChanges(); int id = Convert.ToInt32(Session["KullaniciID"]); int sepette_kalan = db.Sepetim.Where(x => x.Kullanici_ID == id).Count(); return Json(new { IsSuccess = true, UserMessage = "Ürün Sepetinizden kaldırıldı", Remain = sepette_kalan }); } ------------------------------- $(document).on("click", '#SepetimDelete', function () { var gelenID = $(this).attr("data-id"); var silTR = $(this).closest("tr"); $.getJSON('/Sepetim/Sil/' + gelenID) .success(function (response) { silTR.fadeOut(300, function () { $.notify(response.UserMessage, "success"); silTR.remove(); if(response.Remain <= 0) { alert('sepet boşaldı'); //ya da actiona gidin; location = 'Sepetim/SepetBos'; } }); }); })
e-mail: onay[nokta]yalciner[at]hotmail[nokta]com
- Yanıt Olarak Öneren Berkayaylaci 30 Haziran 2016 Perşembe 23:30
- Yanıt Olarak İşaretleyen Kyamuran SalibryamMicrosoft contingent staff, Moderator 13 Temmuz 2016 Çarşamba 22:12
-
Hocam teşekkür ederim vaktinizi ayırdığınız için. yardımınız işime yaradı.$.getJSON'nu $.post olarak değiştirdim çünkü getJSON'ken şöyle bi hata verdi "Failed to load resource: the server responded with a status of 500 (Internal Server Error)" tekrar çok teşekkür ederim.
-