【发布时间】:2017-04-25 05:36:05
【问题描述】:
我将我的 anguler 模型发布到 mvc HttpPost ActionResult。在我想重定向操作联系人视图之后。代码正在运行,但联系人视图未显示。
第一次 ActionResult 调用
$scope.saveSubs = function () {
var sub = {Des: $scope.des.slice($scope.des.lastIndexOf("(") + 1,
$scope.des.lastIndexOf(")")),
};
$http.post('/Home/HotelSearch', sub);
这是有效的。但在这个电话之后,我想重定向到另一个 ActionResult。
HttpPost ActionResult
[HttpPost]
public ActionResult HotelSearch(HotelBooking hotelBooking)
{
ViewBag.Message = "Your contact page.";
TempData["LoginData"] = hotelBooking;
return RedirectToAction("Contact");
}
第二次行动结果
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View("Contact");
}
此视图未查看。我能知道这是什么问题吗?
【问题讨论】:
-
我认为您不能在 Ajax 调用中重定向整个浏览器页面。通常我会在 Ajax 调用返回时返回一个 Partial View 并将其添加到 DOM;或者我返回一个带有 URL 的字符串,以便在 Ajax 调用返回时通过
location.href重定向客户端。 -
ajax 调用 working.second RedirectToAction 未查看。调试点到达。但视图不起作用。
-
将 jsonresult 返回到您的 ajax 调用,在成功回调中您可以重定向您想要的页面
-
替换 RedirectToAction("Contact"); with View("Contact",model) 其中模型是合同视图所需的填充模型。
标签: asp.net asp.net-mvc asp.net-mvc-4