HTML RenderAction - ActionResult 方法中的重定向

HTML RenderAction - redirection in ActionResult method

RenderAction 请求的控制器内部

@{Html.RenderAction("abc", "Controller"); }

如果出现问题,我正在尝试重定向到一个新的控制器,但是这个重定向被忽略了,所以网站就崩溃了。那么我该如何重定向,因为我在下面完成的代码不起作用?

我想知道它是否与 ChildActionOnly 属性有关?

谢谢

[ChildActionOnly]
public ActionResult abc()
{
   if(....) 
   {
      // if all is OK return this view
      return View("view", ViewModel
      {
           ...
           ...
      });
   }
   else
   {   
      // This is the problem..
      return RedirectToAction("LogOn", "controller");
   }

}

子操作无法执行重定向。

一种替代方法是在您的主视图中使用 JavaScript(在下面的示例中使用 jQuery)来执行对该方法的请求,如果失败,该方法将执行某些操作:

$.ajax({
    url: '@Url.Action("SomeAction")'
}).fail(function() {
    window.location = '@Url.Action("SomethingWentWrong")';
}).done(function(data) {
    // display data
});

然后 return 来自 SomeAction 的 500 错误。