/// <inheritdoc /> public virtual string Action(UrlActionContext actionContext) { if (actionContext == null) { throw new ArgumentNullException(nameof(actionContext)); } var valuesDictionary = PropertyHelper.ObjectToDictionary(actionContext.Values); if (actionContext.Action == null) { object action; if (!valuesDictionary.ContainsKey("action") && AmbientValues.TryGetValue("action", out action)) { valuesDictionary["action"] = action; } } else { valuesDictionary["action"] = actionContext.Action; } if (actionContext.Controller == null) { object controller; if (!valuesDictionary.ContainsKey("controller") && AmbientValues.TryGetValue("controller", out controller)) { valuesDictionary["controller"] = controller; } } else { valuesDictionary["controller"] = actionContext.Controller; } var path = GeneratePathFromRoute(valuesDictionary); if (path == null) { return(null); } return(GenerateUrl(actionContext.Protocol, actionContext.Host, path, actionContext.Fragment)); }
/// <inheritdoc /> public virtual string Action(UrlActionContext actionContext) { if (actionContext == null) { throw new ArgumentNullException(nameof(actionContext)); } var valuesDictionary = new RouteValueDictionary(actionContext.Values); if (actionContext.Action == null) { object action; if (!valuesDictionary.ContainsKey("action") && AmbientValues.TryGetValue("action", out action)) { valuesDictionary["action"] = action; } } else { valuesDictionary["action"] = actionContext.Action; } if (actionContext.Controller == null) { object controller; if (!valuesDictionary.ContainsKey("controller") && AmbientValues.TryGetValue("controller", out controller)) { valuesDictionary["controller"] = controller; } } else { valuesDictionary["controller"] = actionContext.Controller; } var path = GeneratePathFromRoute(routeName: null, values: valuesDictionary); if (path == null) { return null; } return GenerateUrl(actionContext.Protocol, actionContext.Host, path, actionContext.Fragment); }
/// <inheritdoc /> public virtual string Action(UrlActionContext actionContext) { var valuesDictionary = PropertyHelper.ObjectToDictionary(actionContext.Values); if (actionContext.Action == null) { object action; if (!valuesDictionary.ContainsKey("action") && AmbientValues.TryGetValue("action", out action)) { valuesDictionary["action"] = action; } } else { valuesDictionary["action"] = actionContext.Action; } if (actionContext.Controller == null) { object controller; if (!valuesDictionary.ContainsKey("controller") && AmbientValues.TryGetValue("controller", out controller)) { valuesDictionary["controller"] = controller; } } else { valuesDictionary["controller"] = actionContext.Controller; } var path = GeneratePathFromRoute(valuesDictionary); if (path == null) { return null; } return GenerateUrl(actionContext.Protocol, actionContext.Host, path, actionContext.Fragment); }
public void UrlActionWithUrlActionContext_ReturnsExpectedResult() { // Arrange var services = CreateServices(); var urlHelper = CreateUrlHelperWithRouteCollection(services, "/app"); var actionContext = new UrlActionContext() { Action = "contact", Controller = "home3", Values = new { id = "idone" }, Protocol = "ftp", Host = "remotelyhost", Fragment = "somefragment" }; // Act var url = urlHelper.Action(actionContext); // Assert Assert.Equal("ftp://remotelyhost/app/home3/contact/idone#somefragment", url); }
public void UrlActionWithUrlActionContext_ReturnsExpectedResult() { // Arrange var services = GetServices(); var urlHelper = CreateUrlHelperWithRouteCollection(services, "/app"); var actionContext = new UrlActionContext() { Action = "contact", Controller = "home3", Values = new { id = "idone" }, Protocol = "ftp", Host = "remotelyhost", Fragment = "somefragment" }; // Act var url = urlHelper.Action(actionContext); // Assert Assert.Equal("ftp://remotelyhost/app/home3/contact/idone#somefragment", url); }
public override string Action(UrlActionContext actionContext) { return ConvertToLowercaseUrl(base.Action(actionContext)); }