我已經從ajax調用了一個刪除控制器。刪除數據並執行成功功能,但頁面不會重定向到控制器中提到的新頁面。 這裏是我的Ajax代碼:爲什麼不重定向頁面?
function deletex(ids)
{
var x={id:ids};
var a=confirm("are you sure to delete this data of id"+x["id"]);
if(a==true)
{
$.ajax({
type: "POST",
url: "Delete",
data: x,
dataType:"HTML",
success: function (data) {
Set(data);
alert("data is deleted");
},
error:
function e()
{
alert("error");
}
});
} else
alert("You cancelled it");
}
我的控制器:
[HttpPost]
public ActionResult Delete(long id)
{
country country = db.countries.Find(id);
db.countries.Remove(country);
db.SaveChanges();
return RedirectToAction("Create","countries");
}
我認爲它無法解決的網址,你收到什麼控制檯錯誤? – Rex
控制檯中沒有錯誤只是頁面沒有被重定向到控制器中提到的視圖 – Anil
在ajax成功事件中嘗試設置window.location ='@ Url.Action(「Create」,「countries」)' – malkam