【问题标题】:MVC Route return Error : Child actions are not allowed to perform redirect actionsMVC 路由返回错误:不允许子动作执行重定向动作
【发布时间】:2014-10-03 10:31:13
【问题描述】:

我正在使用 nopCommmerce 3.40 ,MVC 5

我已经制作插件并制作了一条路线以供行动

但我得到的错误看起来像:

Error executing child request for handler'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

Child actions are not allowed to perform redirect actions

我的代码

[AdminAuthorize]
    public ActionResult Configure()
    {

       return RedirectToRoute("PluginName.ActionName");
    }

    public ActionResult ActionName()
    {
       // i want to call/ return this  from Configure mathod
    }

路由提供者

routes.MapRoute("PluginName.ActionName", "Admin/Plugins",
                     new { controller = "Controller", action = "Action" },
                     new[] { "PluginName.ActionName.Controllers" }
                     ).DataTokens.Add("area", "admin");

【问题讨论】:

    标签: asp.net-mvc nopcommerce


    【解决方案1】:

    您收到的错误消息说明了一切。您不能在那里执行重定向。实际上,插件配置操作是使用子操作调用的,因此通常使用 [ChildActionOnly] 属性进行修饰。你可以在这个答案Why are Redirect Results not allowed in Child Actions in Asp.net MVC 2找到更详细的消息。

    您应该重构代码以从其他地方调用重定向,例如主操作或应用于主操作的自定义操作过滤器。

    但是,由于调用配置操作的代码属于 nopCommerce,而不是您的插件,因此不受您的控制,您最好的办法是动态注入自定义操作过滤器并在那里执行重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      相关资源
      最近更新 更多