【发布时间】:2014-07-31 19:28:42
【问题描述】:
我已经尝试了很多方法,但都没有运气……我必须离开这里。
这是我的操作链接:
@Ajax.ActionLink("Delete all", "Empty",
new AjaxOptions()
{
HttpMethod = "POST",
OnBegin = String.Format("if(!confirm('Are you sure you want to permanently delete {0} items?')){{return false;}}",ViewBag.TotalItems),
OnComplete = "location.reload()",
}
和我的 ActionResult,我已经尝试了所有注释掉的返回:
public ActionResult Empty()
{
//return Json(new
//{
// redirectUrl = Url.Action("Index", "Home"),
// isRedirect = true
//});
//return RedirectToRoute(new { controller = "Home", action = "Index" });
//return Redirect("http://google.ca");
return RedirectToAction("Index", "Home");
//return new JsonResult() { Data = new { redirectURL = "/" } };
}
但我永远无法让它重定向到任何新页面:/
感谢任何帮助或指导...
编辑:我应该注意,直到最近尝试所有方法后,我才最初使用“OnComplete”行。
【问题讨论】:
-
你还在敲控制器吗?问题不是你的控制器,因为无论发生什么情况都会重定向,所以问题出在
Ajax.ActionLink。还有使用 Ajax.ActionLink 的原因是什么,你只是在处理一个普通的 ActionResult 那么为什么不只使用 Html.Action 并使用 JQUERY 来处理是/否响应。 -
是的,我肯定是在打控制器,我已经设置了断点等。
-
为我工作(MVC5)。为什么是 POST 请求?你在这个控制器中有另一个“空”动作吗?你有“家”控制器吗?
-
代码工作得很好,你确定你只是没有从主页索引视图调用它,而且看起来你没有改变页面吗? POST 将用于删除用户,因为 ActionLink 似乎表示数据库调用。
-
将其更改为 Html ActionLink 有效并且符合我的目的...感谢 Damian。
标签: c# asp.net-mvc asp.net-ajax actionlink actionresult