public void ShouldPutMultipleOptionalRouteValuesAfterSameNamedOnes() { var valuesIn = new Dictionary <string, object> { { "controller", "foo" }, { "action", "bar" }, { "a", RouteParameter.Optional }, { "b", RouteParameter.Optional }, }; var routeValues = new RouteValues(valuesIn); routeValues.Add(new RouteValue("a", "zzz", RouteValueOrigin.Params)); routeValues.Add(new RouteValue("b", "bbb", RouteValueOrigin.Params)); routeValues.Sort(); Assert.That(routeValues.Values[0].Name, Is.EqualTo("a")); Assert.That(routeValues.Values[1].Name, Is.EqualTo("a")); Assert.That(routeValues.Values[0].Value, Is.EqualTo("zzz")); Assert.That(routeValues.Values[1].Value, Is.EqualTo(RouteParameter.Optional)); Assert.That(routeValues.Values[2].Name, Is.EqualTo("b")); Assert.That(routeValues.Values[3].Name, Is.EqualTo("b")); Assert.That(routeValues.Values[2].Value, Is.EqualTo("bbb")); Assert.That(routeValues.Values[3].Value, Is.EqualTo(RouteParameter.Optional)); }
public override IDictionary <string, object> Serialize(IGridUrlBuilder urlBuilder) { var state = base.Serialize(urlBuilder); if (Text.HasValue()) { state["text"] = Text; } if (SendState && !Ajax) { RouteValues.AddRange(urlBuilder.GetState()); } var dataRouteValues = DataRouteValues.Cast <IGridDataKey>(); if (Ajax) { state["ajax"] = true; } if (SendDataKeys) { dataRouteValues = dataRouteValues.Concat(urlBuilder.GetDataKeys()); } foreach (var route in dataRouteValues) { RouteValues[route.RouteKey] = "<#=" + route.Name + "#>"; } state["url"] = urlBuilder.Url(this); return(state); }
public override bool CanBind(string name, Type outerType, IRequest request, RouteValues routeValues, object owner) { if (!outerType.IsGenericType) { return(false); } var genericOuterType = outerType.GetGenericTypeDefinition(); if (genericOuterType != typeof(IEnumerable <>)) { return(false); } var middleType = outerType.GetGenericArguments()[0]; if (!middleType.IsGenericType) { return(false); } var genericMiddleType = middleType.GetGenericTypeDefinition(); if (genericMiddleType != typeof(IEnumerable <>)) { return(false); } var innerType = middleType.GetGenericArguments()[0]; var innerBinder = BinderCollection.FindBinderFor(null, innerType, request, routeValues, owner); return(innerBinder != null); }
public static string Name(RouteValues values) { return string.Format(Format, values.ControllerType.FullName, values.Action, ParameterDescriptions(values.ActionMethodInfo)); }
// GET: Horses/Create //[Authorize] public async Task <IActionResult> Create(int raceId, int laneId) { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); if (user == null) { //Store horse info in session for redirect after login //****CT***** Need to convert this to Router class object HttpContext.Session.SetString("redirect", "true"); HttpContext.Session.SetString("controller", "Horse"); HttpContext.Session.SetString("action", "Create"); RouteValues obj_routeValues = new RouteValues { RaceId = raceId, LaneId = laneId }; var routeValues = JsonConvert.SerializeObject(obj_routeValues); HttpContext.Session.SetString("routeValues", routeValues); return(RedirectToAction("login", "ApplicationUser")); } ViewData["raceId"] = raceId; ViewData["laneId"] = laneId; ViewData["year"] = DateTime.Now.Year; return(View()); }
public ActionResult BasicInfo(ShippingMethodEditorModel model) { var method = model.Id > 0 ? _shippingMethodService.Find(model.Id) : new ShippingMethod(); method.Name = model.Name; method.Description = model.Description; method.ShippingRateProviderName = model.ShippingRateProviderName; if (model.Id == 0) { _shippingMethodService.Create(method); } var shippingRateProvider = _shippingRateProviderFactory.FindByName(method.ShippingRateProviderName); string redirectUrl = null; var editor = shippingRateProvider as IHasCustomShippingRateProviderConfigEditor; if (editor != null || shippingRateProvider.ConfigType != null) { redirectUrl = Url.Action("ShippingRateProvider", RouteValues.From(Request.QueryString).Merge("id", method.Id)); } else { redirectUrl = Url.Action("Complete", RouteValues.From(Request.QueryString).Merge("id", method.Id)); } return(AjaxForm().RedirectTo(redirectUrl)); }
public bool CheckIsActive(bool ignoreAction) { string currentController = ViewContext.RouteData.Values["Controller"].ToString(); string currentAction = ViewContext.RouteData.Values["Action"].ToString(); RouteValueDictionary routeValues = ViewContext.RouteData.Values; var stringComparer = StringComparison.OrdinalIgnoreCase; if (!string.IsNullOrEmpty(Controller) && !string.Equals(Controller, currentController, stringComparer)) { return(false); } if (!ignoreAction && !string.IsNullOrEmpty(Action) && !string.Equals(Action, currentAction, stringComparer)) { return(false); } foreach (var(key, value) in RouteValues) { if (!RouteValues.ContainsKey(key) || RouteValues[key].ToString() != value) { return(false); } } return(true); }
/// <summary> /// Method controls what the tag helper does when executed /// </summary> /// <param name="context">information associated with the execution of the current HTML tag</param> /// <param name="output"> a stateful HTML element representative of the original source used to generate an HTML tag and content</param> public override void Process(TagHelperContext context, TagHelperOutput output) { string querystring = null; // RouteValues is an anonymous type if (RouteValues != null) { var pairs = RouteValues.GetType().GetProperties() .Select(x => x.Name + "=" + x.GetValue(RouteValues, null)); querystring = string.Join("&", pairs); } if (string.IsNullOrEmpty(Culture) || string.IsNullOrWhiteSpace(Culture)) { Culture = "en-US"; } output.Attributes.SetAttribute("href", "/" + Culture + "/" + Controller + "/" + Action + (querystring == null ? string.Empty : "?" + querystring)); output.TagName = "a"; // Replaces <yakor> with <a> tag if (!string.IsNullOrEmpty(Class) && !string.IsNullOrWhiteSpace(Class)) { output.Attributes.SetAttribute("class", Class); } // output.Content.SetContent(address); }
public void Process(RouteValues routeValues, IHttpRequest request, IHttpResponse response, IHttpSession session) { string output = _action.Invoke(new ActionParameters(routeValues, request, response, session)); var writer = new StreamWriter(response.Body); writer.Write(output); writer.Flush(); }
public override bool CanBind(string name, Type type, IRequest request, RouteValues routeValues, object owner) { return(!string.IsNullOrEmpty(request.ContentType) && request.ContentType.ToLowerInvariant() == "application/json" && !request.HttpMethod.IsSafe() && !type.IsValueType); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (!output.Attributes.ContainsName(Href) && !context.AllAttributes.ContainsName("asp-route-lang") && !(RouteValues?.ContainsKey("lang") == true)) { var routeValues = ViewContext?.RouteData?.Values; if (routeValues != null) { var langValue = routeValues["lang"]?.ToString(); if (string.IsNullOrWhiteSpace(langValue)) { langValue = AnchorTagHelperSettings.DefaultCulture; } if (RouteValues == null) { RouteValues = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); } RouteValues.Add("lang", langValue); } } base.Process(context, output); }
private string GeneratePageUrl(int pageNumber) { var routeValues = RouteValues.ToDictionary( kvp => kvp.Key, kvp => (object)kvp.Value, StringComparer.OrdinalIgnoreCase); if (!routeValues.ContainsKey(PageNumberParam)) { routeValues.Add(PageNumberParam, pageNumber); } if (Route != null) { return(urlHelper.Link(Route, routeValues)); } else if (Action != null && Controller != null) { return(urlHelper.Action(Action, Controller, routeValues)); } else if (BaseHref != null) { if (BaseHref.StartsWith("~/")) { BaseHref = urlHelper.Content(BaseHref); } return($"{BaseHref}?{routeValues.Select(x => $"{x.Key}={x.Value}").Aggregate((current, next) => $"{current}&{next}")}"); } return(pageNumber.ToString()); }
/// <summary> /// 初始化当前标签上下文。 /// </summary> /// <param name="context">当前HTML标签上下文,包含当前HTML相关信息。</param> public override void Init(TagHelperContext context) { base.Init(context); if (IconName == null) { if (Icon != IconType.None) { IconName = Icon.ToDescriptionString(); } else { IconName = Type.GetIconClassName(); } } if (!RouteValues.ContainsKey("handler")) { switch (Type) { case ActionType.Delete: case ActionType.MoveUp: case ActionType.MoveDown: case ActionType.Edit: case ActionType.Upload: RouteValues.Add("handler", Type.ToString()); break; } } }
public static void GeneratesActionUrl(RouteCollection routes, HttpMethod httpMethod, string expectedUrl, IDictionary <string, string> fromProps, string appPath = null, string requestBody = null) { var fromRouteValues = new RouteValues(fromProps); WebRouteAssert.GeneratesActionUrl(routes, httpMethod, expectedUrl, fromRouteValues, appPath, requestBody); }
public static HeaderPanelButton AddCreateButton(this HeaderPanelButtonCollection buttons, string actionName = "Create") { var urlHelper = new UrlHelper(buttons.Html.ViewContext.RequestContext); var routeValues = RouteValues.From(buttons.Html.ViewContext.HttpContext.Request.QueryString).Merge("return", buttons.Html.ViewContext.HttpContext.Request.RawUrl); return(buttons.Add("Create", "add", urlHelper.Action(actionName, routeValues))); }
public BindingResult Bind(string name, Type type, IRequest request, RouteValues routeValues, bool isNestedCall, object owner) { var prefix = name + "["; var bindingErrors = new List <BindingError>(); var genericArgument = type.GetGenericArguments()[0]; var list = Activator.CreateInstance(typeof(ExpandableList <>).MakeGenericType(genericArgument)) as IList; foreach (var key in request.Form.AllKeys) { if (key.StartsWith(prefix, true, CultureInfo.InvariantCulture)) { var start = prefix.Length; var end = key.IndexOf(']', start); var index = int.Parse(key.Substring(start, end - start)); var indexedName = name + "[" + index + "]"; var innerBinder = BinderCollection.FindBinderFor(indexedName, genericArgument, request, routeValues, owner); var bind = innerBinder.Bind(indexedName, genericArgument, request, routeValues, true, owner); list[index] = bind.Object; if (bind.Result == BindingResult.ResultType.Failure) { bindingErrors.AddRange(bind.BindingErrors); } } } return(new BindingResult(list, bindingErrors.ToArray(), bindingErrors.Any() ? BindingResult.ResultType.Failure : BindingResult.ResultType.Success)); }
public override IHtmlContent ValueFor(IGridRow <object> row) { object value = GetValueFor(row); if (value == null) { return(HtmlString.Empty); } if (value is IHtmlContent) { return(value as IHtmlContent); } if (FormatExpression != null) { Format = FormatExpression.Invoke((T)row.Model); } if (RouteValues != null) { Format = $"<a href=\"{RouteValues.Invoke((T)row.Model)}\">{Format}</a>"; } if (Format != null) { value = string.Format(Format, value); } if (IsEncoded) { return(new HtmlString(HtmlEncoder.Default.Encode(value.ToString()))); } return(new HtmlString(value.ToString())); }
public static HeaderPanelButton AddAjaxPostButton(this HeaderPanelButtonCollection buttons, string text, string icon, string action, RouteValueDictionary additionalRouteValues) { var urlHelper = new UrlHelper(buttons.Html.ViewContext.RequestContext); var url = urlHelper.Action(action, RouteValues.From(buttons.Html.ViewContext.HttpContext.Request.QueryString).Merge(additionalRouteValues)); return(buttons.Add(text, icon, url) .WithCommandType(CommandType.AjaxPost)); }
public override bool CanBind(string name, Type type, IRequest request, RouteValues routeValues, object owner) { return(request.ContentType != null && request.ContentType.MediaType.ToLowerInvariant() == "application/json" && !request.HttpMethod.IsSafe() && type.IsClass && type != typeof(string)); }
/// <summary> /// Clears a route value set for this link. /// </summary> /// <param name="name">The route value name.</param> public ActionLink ClearRouteValue(string name) { if (RouteValues != null) { RouteValues.Remove(name); } return(this); }
public override void Process(TagHelperContext context, TagHelperOutput output) { Controller = "Claim"; Action = "MyClaim"; RouteValues.Add("ProjectId", For.ProjectId.ToString()); base.Process(context, output); output.TagName = "a"; }
HashKey(string name, Type type, string requestContentType, HttpMethod requestMethod, RouteValues routeValues) { this.Name = name; this.Type = type; this.RequestContentType = requestContentType; this.RequestMethod = requestMethod; this.RouteValues = routeValues; }
public void ReadsEmptyDataWithoutRouteValues() { var data = new Dictionary <string, string>(); var props = new RouteValues(data); Assert.That(props.Values, Is.Not.Null, "route values null"); Assert.That(props.Values.Count, Is.EqualTo(0), "route values empty"); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.Attributes.Remove(output.Attributes.Single(a => a.Name == "asp-for")); Controller = "Claim"; Action = "MyClaim"; RouteValues.Add("ProjectId", For.ProjectId.ToString()); base.Process(context, output); }
protected override string ResolveUrl(RouteValues routeValues, IElasticsearchClientSettings settings) { if (Pit is not null && !string.IsNullOrEmpty(Pit.Id ?? string.Empty) && routeValues.ContainsKey("index")) { routeValues.Remove("index"); } return(base.ResolveUrl(routeValues, settings)); }
public BindingResult Bind(string name, Type type, IRequest request, RouteValues routeValues, bool isNestedCall, object owner) { if (request.HttpMethod == HttpMethod.Post || request.HttpMethod == HttpMethod.Put) { return(this.Bind(type, name, request.Form[name], request, routeValues, owner)); } return(new BindingResult(null, BindingResult.ResultType.Failure)); }
public bool CanBind(string name, Type type, IRequest request, RouteValues routeValues, object owner) { if (type.IsGenericType && type.GenericTypeArguments.Length == 2) { var dictType = typeof(IDictionary <,>).MakeGenericType(type.GenericTypeArguments); return(dictType.IsAssignableFrom(type)); } return(false); }
protected string GetPageLink(int pageNumber, UrlHelper urlHelper) { if (RouteValues != null && !string.IsNullOrEmpty(PageRouteValueName) && RouteValues.ContainsKey(PageRouteValueName)) { RouteValues[PageRouteValueName] = pageNumber; } return(string.IsNullOrEmpty(ActionName) || string.IsNullOrEmpty(ControllerName) ? "#" : urlHelper.Action(ActionName, ControllerName, RouteValues)); }
public ActionParameters(RouteValues routeValues, IHttpRequest request, IHttpResponse response, IHttpSession session) { RouteValues = routeValues; Request = request; Response = response; Session = session; Store = _theStore; }
public virtual void GenerateUrl() { if (!RouteValues.ContainsKey("app")) { RouteValues["app"] = Widget.Ace.AppName; } Url = GetApi(RouteValues); Dynamic = true; }
private static RouteValues RouteValuesContainingId() { var values = new RouteValues(); var idValue = new RouteValue("Id", 42, RouteValueOrigin.Unknown); values.Add(idValue); return(values); }
protected override string ResolveUrl(RouteValues routeValues, IElasticsearchClientSettings settings) { if ((Self.PitValue is not null || Self.PitDescriptor is not null || Self.PitDescriptorAction is not null) && routeValues.ContainsKey("index")) { routeValues.Remove("index"); } return(base.ResolveUrl(routeValues, settings)); }
public void FailsAreReported() { var data = new Dictionary <string, string>(); var routeValues = new RouteValues(data); routeValues.CheckDataOk(); Assert.That(assertEngine.FailCount, Is.EqualTo(2)); Assert.That(routeValues.DataOk, Is.False); }
public void CreateValues() { Argument1 = "1"; Argument2 = 2; _values = RouteValues.Create((MyController controller) => controller.Echo2(Argument1, Argument2)); }
private FakeRequestContext buildFakeRequestWithAcceptAndRouteValues(string acceptHeader, RouteValueDictionary values) { var headers = new Mock<IRequestHeaders>(); headers.Setup(x => x[It.IsAny<string>()]).Returns(acceptHeader); var routeValues = new RouteValues(values); return new FakeRequestContext(headers.Object, routeValues); }
private FakeRequestContext buildFakeRequestWithAccept(string acceptHeader) { var headers = new Mock<IRequestHeaders>(); headers.Setup(x => x[It.IsAny<string>()]).Returns(acceptHeader); headers.Setup(x => x.KeyExists(It.IsAny<string>())).Returns(true); var routeValues = new RouteValues(new RouteValueDictionary()); return new FakeRequestContext(headers.Object, routeValues); }
public void CreateValues() { _values = RouteValues.Create((MyController controller) => controller.SayHi()); }
public void CreateValues() { _values = RouteValues.Create((MyEchoController controller) => controller.Echo("hello")); }
public void CreateValues() { _values = RouteValues.Create((MyController controller) => controller.Echo(Argument1)); }
public void CreateValues() { var valueHolder = new ValueHolder() {Value = "hello"}; _values = RouteValues.Create((MyEchoController controller) => controller.Echo(valueHolder.Value)); }