GetRouteUrl() public method

public GetRouteUrl ( RouteValueDictionary routeParameters ) : string
routeParameters RouteValueDictionary
return string
        // Format will be <%$ ExpPrefix: RouteName = <name>, Key=Value, Key2=Value2 %>
        public static string GetRouteUrl(Control control, string expression) {
            if (control == null) {
                throw new ArgumentNullException("control");
            }

            string routeName = null;
            RouteValueDictionary routeParams = new RouteValueDictionary();
            if (TryParseRouteExpression(expression, routeParams, out routeName)) {
                return control.GetRouteUrl(routeName, routeParams);
            }
            else {
                throw new InvalidOperationException(SR.GetString(SR.RouteUrlExpression_InvalidExpression));
            }
        }
 public static string GetRouteUrl(Control control, string expression)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     string routeName = null;
     RouteValueDictionary routeValues = new RouteValueDictionary();
     if (!TryParseRouteExpression(expression, routeValues, out routeName))
     {
         throw new InvalidOperationException(System.Web.SR.GetString("RouteUrlExpression_InvalidExpression"));
     }
     return control.GetRouteUrl(routeName, routeValues);
 }
Beispiel #3
0
		public static void GetRouteUrl_String_RouteValueDictionary_Load (Page p)
		{
			RouteTable.Routes.Clear ();

			var ctl = new Control ();
			var rvd = new RouteValueDictionary {
				{"foo", "one"},
				{"bar", "two"}
			};
			string path;
			AssertExtensions.Throws<ArgumentException> (() => {
				path = ctl.GetRouteUrl ("myroute", rvd);
			}, "#A1");

			RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
			RouteTable.Routes.Add ("myroute", new Route ("{bar}-{foo}", new PageRouteHandler ("~/default.aspx")));
			path = ctl.GetRouteUrl ("myroute", rvd);
			Assert.IsNotNull (path, "#A2-1");
			Assert.AreEqual ("/NunitWeb/two-one", path, "#A2-2");

			path = ctl.GetRouteUrl ("myroute", (RouteValueDictionary) null);
			Assert.IsNull (path, "#A3-1");

			path = ctl.GetRouteUrl (null, (RouteValueDictionary) null);
			Assert.IsNull (path, "#A3-2");

			path = ctl.GetRouteUrl (String.Empty, (RouteValueDictionary) null);
			Assert.IsNull (path, "#A3-3");
		}
Beispiel #4
0
		public static void GetRouteUrl_String_Object_Load (Page p)
		{
			RouteTable.Routes.Clear ();

			var ctl = new Control ();
			object obj = new { foo = "one", bar = "two" };
			string path;
			AssertExtensions.Throws<ArgumentException> (() => {
				path = ctl.GetRouteUrl ("myroute1", obj);
			}, "#A1");

			RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
			RouteTable.Routes.Add ("myroute1", new Route ("{bar}-{foo}", new PageRouteHandler ("~/default.aspx")));
			path = ctl.GetRouteUrl ("myroute1", obj);
			Assert.IsNotNull (path, "#A2-1");
			Assert.AreEqual ("/NunitWeb/two-one", path, "#A2-2");

			path = ctl.GetRouteUrl ("myroute1", (object) null);
			Assert.IsNull (path, "#A3");
		}
Beispiel #5
0
		public static void GetRouteUrl_RouteValueDictionary_Load (Page p)
		{
			RouteTable.Routes.Clear ();

			var ctl = new Control ();
			var rvd = new RouteValueDictionary {
				{"foo", "one"},
				{"bar", "two"}
			};
			string path = ctl.GetRouteUrl (rvd);
			Assert.IsNull (path, "#A1");

			RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
			path = ctl.GetRouteUrl (rvd);
			Assert.IsNotNull (path, "#A2-1");
			Assert.AreEqual ("/NunitWeb/one-two", path, "#A2-2");

			path = ctl.GetRouteUrl ((RouteValueDictionary) null);
			Assert.IsNull (path, "#A3");
		}
Beispiel #6
0
		public static void GetRouteUrl_Object_Load (Page p)
		{
			RouteTable.Routes.Clear ();

			var ctl = new Control ();
			object obj = new { foo = "one", bar = "two" };
			string path = ctl.GetRouteUrl (obj);
			Assert.IsNull (path, "#A1");

			RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
			path = ctl.GetRouteUrl (obj);
			Assert.IsNotNull (path, "#A2-1");
			Assert.AreEqual ("/NunitWeb/one-two", path, "#A2-2");

			path = ctl.GetRouteUrl ((object)null);
			Assert.IsNull (path, "#A3");
		}
		public static string GetRouteUrl (Control control, string expression)
		{
			if (control == null)
				throw new ArgumentNullException ("control");
			
			string routeName;
			var rvd = new RouteValueDictionary ();
			
			if (!TryParseRouteExpression (expression, rvd, out routeName))
				throw new InvalidOperationException ("Invalid expression, RouteUrlExpressionBuilder expects a string with format: RouteName=route,Key1=Value1,Key2=Value2");

			return control.GetRouteUrl (routeName, rvd);
		}