2014-10-03 22 views
3

我使用nopCommmerce 3.40,MVC 5MVC路线返回错误:儿童的行为是不允许进行重定向操作

我必须做的插件,使路由一个路由的行动

但我得到错误的外观像:

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 
    } 

RouteProvider

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

回答

1

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

您应该重构代码以从其他位置调用重定向,例如,应用于主操作的主操作或自定义操作筛选器。

但是,由于调用您的Configure动作的代码因为属于nopCommerce而不属于您的控件,而不属于您的插件,所以最好的办法是动态注入自定义动作过滤器并在其中执行重定向。

相关问题