当前位置: 首页>>代码示例>>C#>>正文


C# RouteBase.IsDirectRoute方法代码示例

本文整理汇总了C#中System.Web.Routing.RouteBase.IsDirectRoute方法的典型用法代码示例。如果您正苦于以下问题:C# RouteBase.IsDirectRoute方法的具体用法?C# RouteBase.IsDirectRoute怎么用?C# RouteBase.IsDirectRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Routing.RouteBase的用法示例。


在下文中一共展示了RouteBase.IsDirectRoute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRouteData

        private static RouteData CreateRouteData(RouteBase route, RouteValueDictionary routeValues, RouteValueDictionary dataTokens, ViewContext parentViewContext)
        {
            RouteData routeData = new RouteData();

            foreach (KeyValuePair<string, object> kvp in routeValues)
            {
                routeData.Values.Add(kvp.Key, kvp.Value);
            }

            foreach (KeyValuePair<string, object> kvp in dataTokens)
            {
                routeData.DataTokens.Add(kvp.Key, kvp.Value);
            }

            routeData.Route = route;
            routeData.DataTokens[ControllerContext.ParentActionViewContextToken] = parentViewContext;

            // It's possible that the outgoing route is a direct route - in which case it's not possible to reach using
            // the action name and controller name. We need to check for that case to determine if we need to create a 
            // 'direct route' routedata to reach it.
            if (route.IsDirectRoute())
            {
                // Codeplex-2136 - ControllerContext.IsChildAction returns false inside Controller.Initialize()
                //
                // We're constructing a 'temp' route data to wrap the route data for the match we're invoking via
                // an attribute route. The ControllerContext will look at datatokens to see if it's being invoked
                // as a child action. 
                //
                // By sticking the view context on both route data ControllerContext will do the right thing
                // at all parts of the pipeline.
                var directRouteData = RouteCollectionRoute.CreateDirectRouteMatch(route, new List<RouteData>() { routeData });
                directRouteData.DataTokens[ControllerContext.ParentActionViewContextToken] = parentViewContext;
                return directRouteData;
            }
            else
            {
                return routeData;
            }
        }
开发者ID:drivenet,项目名称:aspnetwebstack,代码行数:39,代码来源:ChildActionExtensions.cs

示例2: CreateRouteData

        private static RouteData CreateRouteData(RouteBase route, RouteValueDictionary routeValues, RouteValueDictionary dataTokens, ViewContext parentViewContext)
        {
            RouteData routeData = new RouteData();

            foreach (KeyValuePair<string, object> kvp in routeValues)
            {
                routeData.Values.Add(kvp.Key, kvp.Value);
            }

            foreach (KeyValuePair<string, object> kvp in dataTokens)
            {
                routeData.DataTokens.Add(kvp.Key, kvp.Value);
            }

            routeData.Route = route;
            routeData.DataTokens[ControllerContext.ParentActionViewContextToken] = parentViewContext;

            // It's possible that the outgoing route is a direct route - in which case it's not possible to reach using
            // the action name and controller name. We need to check for that case to determine if we need to create a 
            // 'direct route' routedata to reach it.
            if (route.IsDirectRoute())
            {
                return RouteCollectionRoute.CreateDirectRouteMatch(route, new List<RouteData>() { routeData });
            }
            else
            {
                return routeData;
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:29,代码来源:ChildActionExtensions.cs


注:本文中的System.Web.Routing.RouteBase.IsDirectRoute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。