子操作的ASP.NET MVC路由匹配 [英] ASP.NET MVC Route matching for child actions

查看:73
本文介绍了子操作的ASP.NET MVC路由匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

子操作的路由匹配方法是否与通常的操作不同?换句话说,子级操作是否具有一些自动生成的url,以使匹配与父级操作类似?

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 done for parent actions?

推荐答案

父级或子级操作处理之间没有区别

任何操作都遵循您在Application_Start中设置的相同路由定义.这意味着父母的行动以及孩子的行动.如果为应用程序中的所有操作提供了特定的路由,则还必须为子操作提供路由定义.

No difference between parent or child action processing

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.

当然可以.子操作与父操作经过相同的MVC处理.如果您可以将Html.RenderAction()更改为Html.RenderPartial(),则当然是不同的.这些不需要经过相同的处理,因此速度要快得多.仅当您无法通过其他方式进行操作或以其他方式进行操作(会增加视图的模型类型的复杂性等)时,才使用Html.RenderAction().

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()的代码,它将调用上下文处理以像对服务器发出请求那样执行:

If 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);

我们可以确定它使用了从MvcHandler继承的ChildActionMvcHandler处理程序,但是在执行方面基本上与它没有区别,因为它没有与处理相关的任何新功能或更改过的功能.因此,它基本上执行了MvcHandler的代码.

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.

这篇关于子操作的ASP.NET MVC路由匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆