本文整理汇总了C#中RouteValueDictionary.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary.Merge方法的具体用法?C# RouteValueDictionary.Merge怎么用?C# RouteValueDictionary.Merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteValueDictionary
的用法示例。
在下文中一共展示了RouteValueDictionary.Merge方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitModuleMenuItem
private static void InitModuleMenuItem(MenuItem menuItem, UrlHelper moduleUrlHelper, string moduleName, string scaffoldController, string scaffoldAction, RouteValueDictionary scaffoldRouteValues, string siteName)
{
var routeValues = new RouteValueDictionary(menuItem.RouteValues);
routeValues.Merge("SiteName", siteName);
routeValues.Merge("ModuleName", moduleName);
var moduleUrl = moduleUrlHelper.Action(menuItem.Action, menuItem.Controller, routeValues);
moduleUrl = ModuleUrlHelper.RemoveApplicationPath(moduleUrl, moduleUrlHelper.RequestContext.HttpContext.Request.ApplicationPath);
menuItem.Controller = scaffoldController;
menuItem.Action = scaffoldAction;
menuItem.RouteValues = scaffoldRouteValues != null ? new RouteValueDictionary(scaffoldRouteValues) : new RouteValueDictionary();
menuItem.RouteValues.Merge("ModuleUrl", moduleUrl);
menuItem.RouteValues.Merge("ModuleName", moduleName);
if (menuItem.Items != null && menuItem.Items.Count > 0)
{
foreach (var item in menuItem.Items)
{
InitModuleMenuItem(item, moduleUrlHelper, moduleName, scaffoldController, scaffoldAction, scaffoldRouteValues, siteName);
}
}
var isCurrentModule = moduleUrlHelper.RequestContext.GetRequestValue("ModuleName").EqualsOrNullEmpty(moduleName, StringComparison.OrdinalIgnoreCase);
menuItem.IsActive = menuItem.IsActive && isCurrentModule;
menuItem.IsCurrent = isCurrentModule;
}
示例2: Generate
public static string Generate(RequestContext requestContext, NavigationRequest navigationItem)
{
var routeValues = new RouteValueDictionary();
if (navigationItem.RouteValues.Any())
routeValues.Merge(navigationItem.RouteValues);
return Generate(requestContext, navigationItem, routeValues);
}
示例3: Generate
public Uri Generate(RequestContext requestContext, INavigatable navigatable)
{
var routeValues = new RouteValueDictionary();
if (navigatable.RouteValues.Any())
{
routeValues.Merge(navigatable.RouteValues);
}
return Generate(requestContext, navigatable, routeValues);
}
示例4: Generate
public string Generate(RequestContext requestContext, INavigatable navigationItem)
{
RouteValueDictionary routeValues = new RouteValueDictionary();
if (navigationItem.RouteValues.Any())
{
routeValues.Merge(navigationItem.RouteValues);
}
return Generate(requestContext, navigationItem, routeValues);
}
示例5: Generate
private static string Generate(RequestContext requestContext, SiteMapNode navigationItem)
{
var routeValues = new RouteValueDictionary();
if (navigationItem.RouteValues.Any())
{
routeValues.Merge(navigationItem.RouteValues);
}
return Generate(requestContext, navigationItem, routeValues);
}
示例6: ExtractControllerAndActionParams
private static void ExtractControllerAndActionParams(RouteValueDictionary routeValues, out object controllerName, out object actionName, RouteValueDictionary source)
{
const string controllerParamName = "controller";
const string actionParamName = "action";
source.TryGetValue(controllerParamName, out controllerName);
source.TryGetValue(actionParamName, out actionName);
source.Remove(controllerParamName);
source.Remove(actionParamName);
routeValues.Merge(source);
}
示例7: Merge_WithRouteValueDictionaries_GivesTargetPrecedence
public void Merge_WithRouteValueDictionaries_GivesTargetPrecedence() {
// Arrange
var source = new RouteValueDictionary() { { "foo", "foovalue" }, { "bar", "barvalue" } };
var target = new RouteValueDictionary() { { "foo", "foovalue2" }, { "baz", "bazvalue" } };
// Act
var merged = source.Merge(target);
// Assert
PAssert.IsTrue(() => merged.Count == 3);
PAssert.IsTrue(() => (string)merged["foo"] == "foovalue2");
PAssert.IsTrue(() => (string)merged["bar"] == "barvalue");
PAssert.IsTrue(() => (string)merged["baz"] == "bazvalue");
}
示例8: PrepareRouteValues
public RouteValueDictionary PrepareRouteValues(RouteValueDictionary routeValues)
{
RouteValueDictionary result = new RouteValueDictionary(routeValues);
result.Merge(grid.ViewContext.RouteData.Values, false);
if (grid.EnableCustomBinding)
{
result[grid.Prefix(GridUrlParameters.PageSize)] = grid.PageSize;
}
foreach (string key in grid.ViewContext.HttpContext.Request.QueryString)
{
if (key != null && !result.ContainsKey(key))
{
result[key] = grid.ViewContext.HttpContext.Request.QueryString[key];
}
}
return result;
}
示例9: Generate
public string Generate(RequestContext requestContext, INavigationItem navigationItem)
{
Guard.IsNotNull(requestContext, "requestContext");
Guard.IsNotNull(navigationItem, "navigationItem");
UrlHelper urlHelper = new UrlHelper(requestContext);
Func<RouteValueDictionary> getRouteValues = () =>
{
RouteValueDictionary routeValues = new RouteValueDictionary();
if (!navigationItem.RouteValues.IsNullOrEmpty())
{
routeValues.Merge(navigationItem.RouteValues);
}
return routeValues;
};
string generatedUrl = null;
if (!string.IsNullOrEmpty(navigationItem.RouteName))
{
generatedUrl = urlHelper.RouteUrl(navigationItem.RouteName, getRouteValues());
}
else if (!string.IsNullOrEmpty(navigationItem.ControllerName) && !string.IsNullOrEmpty(navigationItem.ActionName))
{
generatedUrl = urlHelper.Action(navigationItem.ActionName, navigationItem.ControllerName, getRouteValues());
}
else if (!string.IsNullOrEmpty(navigationItem.Url))
{
generatedUrl = navigationItem.Url.StartsWith("~/", StringComparison.Ordinal) ?
urlHelper.Content(navigationItem.Url) :
navigationItem.Url;
}
return generatedUrl;
}
示例10: GetActionParams
private static void GetActionParams(RouteValueDictionary routeValues, out object actionName, out object controllerName, RouteValueDictionary values)
{
routeValues.TryGetValue("action", out actionName);
routeValues.TryGetValue("controller", out controllerName);
routeValues.Remove("action");
routeValues.Remove("controller");
values.Merge(routeValues);
}
示例11: Pager
public static string Pager(this HtmlHelper helper, string actionName, string controllerName, object routeValues, Pager pager)
{
//only one
TagBuilder div = new TagBuilder("div");
div.MergeAttribute("class", "pager");
//only one
TagBuilder ul = new TagBuilder("ul");
ul.MergeAttribute("class", "pager-list");
//multiple items
TagBuilder li = new TagBuilder("li");
li.MergeAttribute("class", "pager-item");
//multiple items
TagBuilder a = new TagBuilder("a");
StringBuilder sb = new StringBuilder();
RouteValueDictionary dict = new RouteValueDictionary(routeValues);
UrlHelper uh = new UrlHelper(helper.ViewContext.RequestContext);
//do it
if(pager.HasPrevPage)
{
a.MergeAttribute("href", uh.Action(actionName, controllerName, dict.Merge(new { page = 1 })), true);
a.SetInnerText("Erste");
li.InnerHtml = a.ToString();
sb.AppendLine(li.ToString());
a.MergeAttribute("href", uh.Action(actionName, controllerName, dict.Merge(new { page = pager.PageIndex - 1 })), true);
a.SetInnerText("« Zurück");
li.InnerHtml = a.ToString();
sb.AppendLine(li.ToString());
}
for (long page = ((pager.PageIndex - 3) <= 0 ? 1 : pager.PageIndex - 3); page <= ((pager.PageIndex + 3) >= pager.TotalPages ? pager.TotalPages : pager.PageIndex + 3); ++page)
{
a.MergeAttribute("href", uh.Action(actionName, controllerName, dict.Merge(new { page = page })), true);
a.SetInnerText(page.ToString());
li.InnerHtml = a.ToString();
sb.AppendLine(li.ToString());
}
if (pager.HasNextPage)
{
a.MergeAttribute("href", uh.Action(actionName, controllerName, dict.Merge(new { page = pager.PageIndex + 1 })), true);
a.SetInnerText("Weiter »");
li.InnerHtml = a.ToString();
sb.AppendLine(li.ToString());
a.MergeAttribute("href", uh.Action(actionName, controllerName, dict.Merge(new { page = pager.TotalPages })), true);
a.SetInnerText("Letzte");
li.InnerHtml = a.ToString();
sb.AppendLine(li.ToString());
}
ul.InnerHtml = sb.ToString();
div.InnerHtml = ul.ToString();
string ret = div.ToString();
return ret;
}
示例12: PrepareRouteData
private RouteValueDictionary PrepareRouteData(IDictionary<string, object> routeValues)
{
var routes = new RouteValueDictionary(routeValues);
var routeData = new RouteValueDictionary(grid.ViewContext.RouteData.Values
.Where(routeValue => !String.Equals("Theme", routeValue.Key))
.ToDictionary(routeValue => routeValue.Key,
routeValue => routeValue.Value));
routes.Merge(routeData, false);
var collection = grid.ViewContext.HttpContext.Request.QueryString;
foreach (var key in collection.AllKeys.Except(routes.Keys))
{
routes[key] = collection[key];
}
return routes;
}