本文整理匯總了C#中System.Web.UI.Control.GetRouteUrl方法的典型用法代碼示例。如果您正苦於以下問題:C# Control.GetRouteUrl方法的具體用法?C# Control.GetRouteUrl怎麽用?C# Control.GetRouteUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.UI.Control
的用法示例。
在下文中一共展示了Control.GetRouteUrl方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetRouteUrl
// 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));
}
}
示例2: GetRouteUrl
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);
}
示例3: GetRouteUrl_String_RouteValueDictionary_Load
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");
}
示例4: GetRouteUrl_String_Object_Load
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");
}
示例5: GetRouteUrl_RouteValueDictionary_Load
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");
}
示例6: GetRouteUrl_Object_Load
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");
}
示例7: GetRouteUrl
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);
}