本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}