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


C# RouteValueDictionary.ToQueryString方法代码示例

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


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

示例1: GetRouteValues

        private static RouteValueDictionary GetRouteValues(HtmlHelper helper, ContentItem item, string controllerName)
        {
            var values = new RouteValueDictionary();
            values[ContentRoute.ControllerKey] = controllerName;
            values[ContentRoute.ActionKey] = "Index";
            values[ContentRoute.ContentItemKey] = item.ID;

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

            values["area"] = vpd.DataTokens["area"];
            return values;
        }
开发者ID:sergheizagaiciuc,项目名称:n2cms,代码行数:15,代码来源:TemplateRenderer.cs

示例2: GetRouteValues

        private RouteValueDictionary GetRouteValues(HtmlHelper helper, ContentItem item)
        {
            Type itemType = item.GetContentType();
            string controllerName = controllerMapper.GetControllerName(itemType);
            if (string.IsNullOrEmpty(controllerName))
            {
                Trace.TraceWarning("Found no controller for type " + itemType);
                return null;
            }

            var values = new RouteValueDictionary();
            values[ContentRoute.ActionKey] = "Index";
            values[ContentRoute.ControllerKey] = controllerName;
            values[ContentRoute.ContentItemKey] = item;

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

            values["area"] = vpd.DataTokens["area"];
            return values;
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:23,代码来源:TemplateRenderer.cs

示例3: GetVirtualPath

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            ContentItem item;

            Debug.WriteLine("GetVirtualPath for values: " + values.ToQueryString());

            values = new RouteValueDictionary(values);

            // try retrieving the item from the route values
            if (!TryConvertContentToController(requestContext, values, ContentItemKey, out item))
            {
                // no item was passed, fallback to current content item
                item = requestContext.CurrentItem();

                if (item == null)
                    // no item = no play
                    return null;

                if (!RequestedControllerMatchesItemController(values, item))
                    // someone's asking for a specific controller so we let another route handle it
                    return null;
            }

            if (item.IsPage)
                return ResolveContentActionUrl(requestContext, values, item);

            // try to find an appropriate page to use as path (part data goes into the query strings)
            ContentItem page = values.CurrentItem<ContentItem>(ContentPageKey, engine.Persister);
            if (page != null)
                // a page parameter was passed
                return ResolvePartActionUrl(requestContext, values, page, item);

            page = requestContext.CurrentPage<ContentItem>();
            if (page != null && page.IsPage)
                // next use the current page
                return ResolvePartActionUrl(requestContext, values, page, item);

            page = item.ClosestPage();
            if (page != null && page.IsPage)
                // fallback to finding the closest page
                return ResolvePartActionUrl(requestContext, values, page, item);

            // can't find a page, don't link
            return null;
        }
开发者ID:spmason,项目名称:n2cms,代码行数:45,代码来源:ContentRoute.cs

示例4: GetVirtualPath

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            // here we deal with people linking to non-n2 controllers but we have merged route values containing n2 stuff
            // scenarios:
            // controller: other -> not our business
            // controller: self -> link to same acton and page
            // acton: other -> link to action on same page
            // item: other -> link to other page
            // nuthin' -> link to same acton and page
            // x: y -> add parameter x
            // page: other -> not our business
            // item: other & action: other -> link to action other page
            // item: other & action: other & x:y-> link to action other page with param
            // app in virtual dir

            values = new RouteValueDictionary(values);

            if (logger.IsDebugEnabled)
                logger.Debug("GetVirtualPath for values: " + values.ToQueryString());

            var contextPath = requestContext.RouteData.CurrentPath();
            var requestedItem = values.CurrentItem<ContentItem>(ContentItemKey, engine.Persister);
            var item = requestedItem;

            if (item == null)
                // fallback to context item
                item = contextPath.CurrentItem;
            else
                // remove specified item from collection so it doesn't appear in the url
                values.Remove(ContentItemKey);

            if (item == null)
                // no item requested or in context .> not our bisiness
                return null;

            var contextController = (string)requestContext.RouteData.Values["controller"];
            var requestedController = (string)values["controller"];
            if (requestedItem == null && requestedController != null)
            {
                if (!string.Equals(requestedController, contextController, StringComparison.InvariantCultureIgnoreCase))
                    // no item was specificlly requested, and the controller differs from context's -> we let some other route handle this
                    return null;

                if (!controllerMapper.IsContentController(requestedController))
                    // same controller not content controller -> let it be
                    return null;
            }

            var itemController = controllerMapper.GetControllerName(item.GetContentType());
            values["controller"] = itemController;

            if (item.IsPage)
                return ResolveContentActionUrl(requestContext, values, item);

            // try to find an appropriate page to use as path (part data goes into the query strings)
            var page = values.CurrentItem<ContentItem>(ContentPageKey, engine.Persister)
                ?? contextPath.CurrentPage
                ?? item.ClosestPage();

            if (page != null)
                return ResolvePartActionUrl(requestContext, values, page, item);

            // can't find a page, don't link
            return null;
        }
开发者ID:Earthware,项目名称:n2cms,代码行数:65,代码来源:ContentRoute.cs


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