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


C# RouteData.ApplyCurrentItem方法代码示例

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


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

示例1: AnalyzeView

        private ViewTemplateDescription AnalyzeView(HttpContextBase httpContext, VirtualFile file, string controllerName, Type modelType)
        {
            if (modelType == null || !typeof(ContentItem).IsAssignableFrom(modelType) || modelType.IsAbstract)
                return null;

            var model = Activator.CreateInstance(modelType) as ContentItem;

            var rd = new RouteData();
            bool isPage = model.IsPage;
            rd.ApplyCurrentItem(controllerName, Path.GetFileNameWithoutExtension(file.Name), isPage ? model : new StubItem(), isPage ? null : model);

            var cctx = new ControllerContext(httpContext, rd, new StubController());

            var result = isPage
                ? viewEnginesProvider.Get().FindView(cctx, file.VirtualPath, null)
                : viewEnginesProvider.Get().FindPartialView(cctx, file.VirtualPath);

            if (result.View == null)
                return null;

            return RenderViewForRegistration(file, modelType, cctx, result);
        }
开发者ID:amarwadi,项目名称:n2cms,代码行数:22,代码来源:ViewTemplateAnalyzer.cs

示例2: CreateHtmlHelper

 private static HtmlHelper CreateHtmlHelper(ContentItem item, TextWriter writer)
 {
     var httpContext = new HttpContextWrapper(HttpContext.Current);
     var routeData = new RouteData();
     routeData.ApplyCurrentItem("webforms", "index", item.ClosestPage(), item);
     return new HtmlHelper(
         new ViewContext(
             new ControllerContext() { HttpContext = httpContext, RequestContext = new RequestContext(httpContext, routeData), RouteData = routeData },
             new WebFormView(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath),
             new ViewDataDictionary(),
             new TempDataDictionary(),
             writer),
         new ViewPage(),
         RouteTable.Routes);
 }
开发者ID:timothyyip,项目名称:n2cms,代码行数:15,代码来源:DisplayableTokensAttribute.cs

示例3: GetRouteDataForPath

        private RouteData GetRouteDataForPath(HttpRequestBase request)
        {
            //On a multi-lingual site with separate domains per language,
            //the full url (with host) should be passed to UrlParser.ResolvePath():
            string host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority;
            string hostAndRawUrl = String.Format("{0}://{1}{2}", request.Url.Scheme, host, Url.ToAbsolute(request.AppRelativeCurrentExecutionFilePath));
            PathData td = engine.UrlParser.ResolvePath(hostAndRawUrl);

            var page = td.CurrentPage;

            var actionName = td.Action;
            if (string.IsNullOrEmpty(actionName))
                actionName = request.QueryString["action"] ?? "Index";

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey]))
            {
                int pageId;
                if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId))
                {
                    td.CurrentPage = page = engine.Persister.Get(pageId);
                }
            }

            ContentItem part = null;
            if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey]))
            {
                // part in query string is used to render a part
                int partId;
                if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId))
                    td.CurrentItem = part = engine.Persister.Get(partId);
            }

            if (page == null && part == null)
                return null;
            else if (page == null)
                page = part.ClosestPage();

            var controllerName = controllerMapper.GetControllerName((part ?? page).GetContentType());

            if (controllerName == null)
                return null;

            if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName))
                return null;

            var data = new RouteData(this, routeHandler);

            foreach (var defaultPair in innerRoute.Defaults)
                data.Values[defaultPair.Key] = defaultPair.Value;
            foreach (var tokenPair in innerRoute.DataTokens)
                data.DataTokens[tokenPair.Key] = tokenPair.Value;

            data.ApplyCurrentItem(controllerName, actionName, page, part);
            data.DataTokens[ContentEngineKey] = engine;

            return data;
        }
开发者ID:spmason,项目名称:n2cms,代码行数:57,代码来源:ContentRoute.cs

示例4: CreateRouteData

            private RouteData CreateRouteData()
            {
                ContentItem page = item;
                var ic = Page as IItemContainer;
                if (ic != null)
                    page = ic.CurrentItem;

                var rd = new RouteData();
                rd.ApplyCurrentItem("webform", "Index", page, item);
                return rd;
            }
开发者ID:cherylhanlon,项目名称:Tigers,代码行数:11,代码来源:MvcOnWebFormPartAdapter.cs

示例5: GetRouteData

            private RouteData GetRouteData(RequestContext requestContext, ContentItem item, string controllerName)
            {
                var data = new RouteData();
                data.Values[ContentRoute.ControllerKey] = controllerName;
                data.Values[ContentRoute.ActionKey] = "Index";
                data.Values[ContentRoute.ContentItemKey] = item.ID;

                // retrieve the virtual path so we can figure out if this item is routed through an area
                var vpd = routes.GetVirtualPath(requestContext, data.Values);
                if (vpd == null)
                    throw new InvalidOperationException("Unable to render " + item + " (" + data.Values.ToQueryString() + " did not match any route)");

                data.Values["area"] = vpd.DataTokens["area"];
                data.Route = vpd.Route;
                data.ApplyCurrentItem(item.ClosestPage(), item);
                return data;
            }
开发者ID:deckhand,项目名称:n2cms,代码行数:17,代码来源:MvcOnWebFormPartAdapter.cs


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