示例#1
0
        /// <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));
        }
示例#2
0
        /// <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);
        }
示例#3
0
文件: UrlHelper.cs 项目: notami18/Mvc
        /// <inheritdoc />
        public virtual string Action(UrlActionContext actionContext)
        {
            var valuesDictionary = PropertyHelper.ObjectToDictionary(actionContext.Values);

            if (actionContext.Action != null)
            {
                valuesDictionary["action"] = actionContext.Action;
            }

            if (actionContext.Controller != null)
            {
                valuesDictionary["controller"] = actionContext.Controller;
            }

            var path = GeneratePathFromRoute(valuesDictionary);
            if (path == null)
            {
                return null;
            }

            return GenerateUrl(actionContext.Protocol, actionContext.Host, path, actionContext.Fragment);
        }
示例#4
0
        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);
        }
示例#5
0
文件: UrlHelper.cs 项目: zt97/Mvc
        /// <inheritdoc />
        public virtual string Action(UrlActionContext actionContext)
        {
            var valuesDictionary = PropertyHelper.ObjectToDictionary(actionContext.Values);

            if (actionContext.Action != null)
            {
                valuesDictionary["action"] = actionContext.Action;
            }

            if (actionContext.Controller != null)
            {
                valuesDictionary["controller"] = actionContext.Controller;
            }

            var path = GeneratePathFromRoute(valuesDictionary);

            if (path == null)
            {
                return(null);
            }

            return(GenerateUrl(actionContext.Protocol, actionContext.Host, path, actionContext.Fragment));
        }
示例#6
0
 public override string Action(UrlActionContext actionContext)
 {
     return ConvertToLowercaseUrl(base.Action(actionContext));
 }
 public string Action(UrlActionContext actionContext)
 {
     throw new NotImplementedException();
 }
示例#8
0
        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);
        }
示例#9
0
 public string Action(UrlActionContext actionContext)
 {
     throw new NotImplementedException();
 }