Does the approach of route matching for child actions differ from usual actions? In other words, do child actions have some autogenerated url to make matching similar to what is
Any action follows the same route definition you've set in your Application_Start
. That means parent actions as well as child ones. If you gave specific routes for all actions in your application, then you must provide route definitions for your child actions as well.
Html.RenderPartial()
If you can of course... Child actions go through the same MVC processing as parent actions. It's of course different if you can change your Html.RenderAction()
to Html.RenderPartial()
. These don't go through the same processing hence are much much faster. Use Html.RenderAction()
only when you can't do it any other way or doing it in other way would be to hackish (increased complexity of the view's model type etc).
Html.RenderAction()
code excerptIf you look at the code of Html.RenderAction()
it calls into context processing to execute as if a request was made to the server:
// other code before this
RouteData routeData = CreateRouteData(data.Route, routeValues, data.DataTokens, htmlHelper.ViewContext);
HttpContextBase httpContext = htmlHelper.ViewContext.HttpContext;
RequestContext context = new RequestContext(httpContext, routeData);
ChildActionMvcHandler httpHandler = new ChildActionMvcHandler(context);
httpContext.Server.Execute(HttpHandlerUtil.WrapForServerExecute(httpHandler), textWriter, true);
We can se that it uses ChildActionMvcHandler
handler which is inherited from MvcHandler
, but is basically no different from it in terms of execution, because it doesn't have any new or changed functionality related to processing. So it executes MvcHandler's code basically.
Child actions execute as parent actions, using the same routing definitions, controller action matching (action method selectors), filters etc.