本文整理汇总了C#中RouteValueDictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary.Remove方法的具体用法?C# RouteValueDictionary.Remove怎么用?C# RouteValueDictionary.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteValueDictionary
的用法示例。
在下文中一共展示了RouteValueDictionary.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: get_link_with_route_data
private static string get_link_with_route_data(HtmlHelper html, int page, bool absolute = true)
{
var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
var action = html.ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();
var controller = html.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
var routeData = new RouteValueDictionary(html.ViewContext.RouteData.Values);
if (page != 1)
{
routeData["page"] = page;
}
else
{
routeData.Remove("page");
}
routeData.Remove("action");
routeData.Remove("controller");
if (absolute)
{
return urlHelper.AbsoluteAction(action, controller, routeData);
}
else
{
return urlHelper.Action(action, controller, routeData);
}
}
示例2: IsValidForRequest
/// <summary>
/// Determines whether the action method selection is valid for the specified
/// controller context.
/// </summary>
/// <param name="controllerContext">The controller context.</param>
/// <param name="methodInfo">Information about the action method.</param>
/// <returns>
/// true if the <see cref="ControllerContext.RouteData"/> has values for
/// all parameters decorated with <see cref="FromRouteAttribute"/>, and if all keys
/// in <see cref="ControllerContext.RouteData"/> match any of the decorated parameters,
/// excluding controller, action and other route parameters that do not map to action method parameters.
/// </returns>
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
var routeValues = new RouteValueDictionary(controllerContext.RouteData.Values);
routeValues.Remove("controller");
routeValues.Remove("action");
CodeRoute codeRoute = controllerContext.RouteData.Route as CodeRoute;
if (codeRoute != null) {
for (int i = 0; i < codeRoute.NonActionParameterTokens.Count; i++) {
routeValues.Remove(codeRoute.NonActionParameterTokens[i]);
}
}
#pragma warning disable 0618
string[] parameters = actionDataCache.GetOrAdd(methodInfo, (m) =>
(from p in m.GetParameters()
where p.IsDefined(typeof(MvcCodeRouting.FromRouteAttribute), inherit: true)
select p.Name).ToArray()
);
#pragma warning restore 0618
return parameters.All(p => routeValues.Keys.Contains(p, StringComparer.OrdinalIgnoreCase))
&& routeValues.Keys.All(k => parameters.Contains(k, StringComparer.OrdinalIgnoreCase));
}
示例3: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
if ((values.ContainsKey(Consts.RouteServiceKey) || requestContext.RouteData.DataTokens.ContainsKey(Consts.RouteServiceKey)) && !values.ContainsKey(Consts.RouteExternalService))
return null;
var tmpValues = new RouteValueDictionary(values);
tmpValues.Remove(Consts.RouteServiceKey);
tmpValues.Remove(Consts.RouteExternalService);
return base.GetVirtualPath(requestContext, tmpValues);
}
示例4: 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);
}
示例5: AddQueryStringToRoute
/// <summary>
/// Adds the current query string to the route value dictionary.
/// </summary>
/// <param name="helper"></param>
/// <param name="values"></param>
/// <param name="request"></param>
/// <returns></returns>
public static RouteValueDictionary AddQueryStringToRoute(this UrlHelper helper, RouteValueDictionary values, HttpRequestBase request, object additionalProperties = null, string[] excludeProperties = null)
{
var rvd = new RouteValueDictionary(values);
if (request != null)
{
foreach (string key in request.QueryString.Keys)
{
rvd[key] = request.QueryString[key].ToString();
}
}
if (additionalProperties != null)
{
var t = additionalProperties.GetType();
foreach (var prop in t.GetProperties())
{
rvd[prop.Name] = prop.GetValue(additionalProperties);
}
}
if (excludeProperties != null)
{
foreach (var prop in excludeProperties)
{
if (rvd[prop] != null)
{
rvd.Remove(prop);
}
}
}
return rvd;
}
示例6: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
if (requestContext.HttpContext.Items.Contains("cmsRouting")) {
values.Remove("controller");
}
return base.GetVirtualPath(requestContext, values);
}
示例7: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
PortalRequestContext context = requestContext.HttpContext.GetPortalContext();
// Remove the "page" from the route data before rerouting
Page page = null;
if(values.ContainsKey("page")) {
// If page is present, but is null, then the user explicitly requested that no page routing be done
page = values["page"] as Page;
if(page == null) {
return null;
}
values.Remove("page");
}
// Reroute the request
VirtualPathData pathData = RerouteRequest(r => r.GetVirtualPath(requestContext, values));
if(pathData == null) {
return null; // Rerouting failed
}
// If we didn't find a page to route the request to, select the active page
if(page == null) {
page = context.ActivePage;
}
// If we still don't have a page, ignore this route
if(page == null) {
return null;
}
// Append the page path to the virtual path received and return the new path
string newVirtualPath = String.Format(CultureInfo.InvariantCulture, "{0}/{1}", page.Path.Substring(1), pathData.VirtualPath).Trim('/');
return new VirtualPathData(this, newVirtualPath);
}
示例8: LowerRouteValues
private static void LowerRouteValues(RouteValueDictionary values)
{
foreach (var key in _requiredKeys)
{
if (values.ContainsKey(key) == false) continue;
var value = values[key];
if (value == null) continue;
var valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
if (valueString == null) continue;
values[key] = valueString.ToLower();
}
var otherKyes = values.Keys
.Except(_requiredKeys, StringComparer.InvariantCultureIgnoreCase)
.ToArray();
foreach (var key in otherKyes)
{
var value = values[key];
values.Remove(key);
values.Add(key.ToLower(), value);
}
}
示例9: TemplateBinder
public TemplateBinder(
UrlEncoder urlEncoder,
ObjectPool<UriBuildingContext> pool,
RouteTemplate template,
RouteValueDictionary defaults)
{
if (urlEncoder == null)
{
throw new ArgumentNullException(nameof(urlEncoder));
}
if (pool == null)
{
throw new ArgumentNullException(nameof(pool));
}
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
_urlEncoder = urlEncoder;
_pool = pool;
_template = template;
_defaults = defaults;
// Any default that doesn't have a corresponding parameter is a 'filter' and if a value
// is provided for that 'filter' it must match the value in defaults.
_filters = new RouteValueDictionary(_defaults);
foreach (var parameter in _template.Parameters)
{
_filters.Remove(parameter.Name);
}
}
示例10: Current
/// <summary>
/// Builds URL by finding the best matching route that corresponds to the current URL, with given parameters added or replaced.
/// </summary>
/// <param name="helper">URL helper.</param>
/// <param name="substitutes">Substitutes.</param>
/// <returns>URL.</returns>
public static IHtmlString Current(this UrlHelper helper, object substitutes)
{
object value = null;
NameValueCollection qs = helper.RequestContext.HttpContext.Request.QueryString;
RouteValueDictionary rd = new RouteValueDictionary(helper.RequestContext.RouteData.Values);
foreach (string param in qs)
{
if (!string.IsNullOrEmpty(qs[param]))
rd[param] = qs[param];
}
if (substitutes != null)
{
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(substitutes.GetType()))
{
value = property.GetValue(substitutes);
if (value == null || string.IsNullOrEmpty(value.ToString()))
rd.Remove(property.Name);
else
rd[property.Name] = value.ToString();
}
}
return new MvcHtmlString(helper.RouteUrl(rd));
}
示例11: GetVirtualPathForArea
public static VirtualPathData GetVirtualPathForArea(this RouteCollection routes, RequestContext requestContext, string name, RouteValueDictionary values) {
if (routes == null) {
throw new ArgumentNullException("routes");
}
if (!String.IsNullOrEmpty(name)) {
// the route name is a stronger qualifier than the area name, so just pipe it through
return routes.GetVirtualPath(requestContext, name, values);
}
RouteValueDictionary valuesWithoutArea = values;
string targetArea = null;
if (values != null) {
object targetAreaRawValue;
if (values.TryGetValue("area", out targetAreaRawValue)) {
targetArea = targetAreaRawValue as string;
// replace the original RVD so that we don't end up with ?area=targetArea in the generated URL
valuesWithoutArea = new RouteValueDictionary(values);
valuesWithoutArea.Remove("area");
}
else {
// set target area to current area
if (requestContext != null) {
targetArea = AreaHelpers.GetAreaName(requestContext.RouteData);
}
}
}
RouteCollection filteredRoutes = FilterRouteCollectionByArea(routes, targetArea);
VirtualPathData vpd = filteredRoutes.GetVirtualPath(requestContext, valuesWithoutArea);
return vpd;
}
示例12: TakeValue
private static string TakeValue(RouteValueDictionary routeValues, string key)
{
if (routeValues.ContainsKey(key))
{
var value = routeValues[key];
routeValues.Remove(key);
return (string)value;
}
return null;
}
示例13: Pager
public Pager(RequestContext requestContext, RouteValueDictionary valuesDictionary, PageInfo pageInfo)
{
this.requestContext = requestContext;
linkWithoutPageValuesDictionary = valuesDictionary;
linkWithoutPageValuesDictionary.Remove("page");
currentPage = pageInfo.Number;
totalItemCount = pageInfo.TotalItemsCount;
pagesCount = pageInfo.PagesCount;
}
示例14: ToRouteValueDictionary
/// <summary>
/// Converts a NameValueCollection into a RouteValueDictionary containing all of the elements in the collection, and optionally appends
/// {newKey: newValue} if they are not null
/// </summary>
/// <param name="collection">NameValue collection to convert into a RouteValueDictionary</param>
/// <param name="newKey">the name of a key to add to the RouteValueDictionary</param>
/// <param name="newValue">the value associated with newKey to add to the RouteValueDictionary</param>
/// <returns>A RouteValueDictionary containing all of the keys in collection, as well as {newKey: newValue} if they are not null</returns>
public static RouteValueDictionary ToRouteValueDictionary(this NameValueCollection collection, string newKey, string newValue)
{
var routeValueDictionary = new RouteValueDictionary();
foreach (var key in collection.AllKeys)
{
if (key == null) continue;
if (routeValueDictionary.ContainsKey(key))
routeValueDictionary.Remove(key);
routeValueDictionary.Add(key, collection[key]);
}
if (string.IsNullOrEmpty(newValue))
{
routeValueDictionary.Remove(newKey);
}
else
{
if (routeValueDictionary.ContainsKey(newKey))
routeValueDictionary.Remove(newKey);
routeValueDictionary.Add(newKey, newValue);
}
return routeValueDictionary;
}
示例15: UpdateRoute
/// <summary>
/// Updates a single parameter in a route value dictionary while leaving other route values the same
/// </summary>
/// <param name="routeValues"></param>
/// <param name="parameter"></param>
/// <param name="value"></param>
/// <returns></returns>
public static RouteValueDictionary UpdateRoute(RouteValueDictionary routeValues, string parameter, string value)
{
if (String.IsNullOrEmpty(value))
{
routeValues.Remove(parameter);
}
else
{
routeValues[parameter] = value;
}
return routeValues;
}