1 回答
TA貢獻(xiàn)1860條經(jīng)驗 獲得超9個贊
您應(yīng)該知道的第一件事是RedirectToAction在 AJAX 調(diào)用中不起作用,您應(yīng)該將 URL 傳遞給重定向,location.href如下所示:
控制器動作
[HttpPost]
public ActionResult Delete(int id)
{
db.Delete<Logs>(id);
// other stuff
string url = this.Url.Action("Index", "Log", new { id = id });
return Json(url);
}
jQuery
$.post("@Url.Action("Delete", "Log")", { id: selectedid }, function (result) {
window.location.href = result;
});
或者更好地創(chuàng)建一個包含要通過 AJAX 更新的所有元素的局部視圖,然后將其傳遞給success部分:
控制器動作
[HttpPost]
public ActionResult Delete(int id)
{
db.Delete<Logs>(id);
// other stuff
return PartialView("PartialViewName");
}
jQuery
$.post("@Url.Action("Delete", "Log")", { id: selectedid }, function (result) {
$('#targetElement').html(result);
});
- 1 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報
