MVC Return Route Error: Child actions are not allowed to perform redirect actions
I am using nopCommmerce 3.40, MVC 5
I have a plugin and route route for an action
But I am getting the error:
Error executing child request for handler'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
Child actions are not allowed to perform redirect actions
My code
[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");
source to share
The error message you get says it all. You cannot redirect there. Plugin customization actions are actually activated using child actions and are therefore usually decorated with the [ChildActionOnly] attribute. You can find a more detailed post in this answer Why Redirect results are not allowed in child activities in Asp.net MVC 2 .
You must refactor your code to trigger a redirect from somewhere else, such as the main activity or a custom action filter applied to the main activity.
But since the code calling your Configure action is out of your control because it belongs to nopCommerce and not your plugin, your best shot is to dynamically inject a custom action filter and redirect there.
source to share