Control.GetRouteUrl 方法

定義

取得 URL,此 URL 對應於一組路由參數,而且會選擇性地對應到路由名稱。Gets the URL that corresponds to a set of route parameters, and optionally to a route name.

多載

GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。Gets the URL that corresponds to a set of route parameters.

GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。Gets the URL that corresponds to a set of route parameters.

GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。Gets the URL that corresponds to a set of route parameters and a route name.

GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。Gets the URL that corresponds to a set of route parameters and a route name.

備註

提供此方法是為了方便撰寫程式碼。This method is provided for coding convenience. 這相當於呼叫 RouteCollection.GetVirtualPath 方法。It is equivalent to calling the RouteCollection.GetVirtualPath method.

GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。Gets the URL that corresponds to a set of route parameters.

public:
 System::String ^ GetRouteUrl(System::Object ^ routeParameters);
public string GetRouteUrl (object routeParameters);
member this.GetRouteUrl : obj -> string
Public Function GetRouteUrl (routeParameters As Object) As String

參數

routeParameters
Object

路由參數。The route parameters.

傳回

對應於指定之路由參數的 URL。The URL that corresponds to the specified route parameters.

範例

下列範例示範如何呼叫 Control.GetRouteUrl 方法,以取得具有 productidcategory之參數的路由 URL。The following example shows how to call the Control.GetRouteUrl method to get the URL of a route that has parameters that are named productid and category. 這個範例假設您已建立名為 HyperLink1HyperLink 控制項。This example assumes that you have created a HyperLink control that is named HyperLink1.

HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl(  
  New With {.productid = "1", .category = "widgets"})  
HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl(  
  new { productid = "1", category = "widgets" });  

備註

提供此方法是為了方便撰寫程式碼。This method is provided for coding convenience. 這相當於呼叫 RouteCollection.GetVirtualPath(RequestContext, RouteValueDictionary) 方法。It is equivalent to calling the RouteCollection.GetVirtualPath(RequestContext, RouteValueDictionary) method. 這個方法會使用 RouteValueDictionary.RouteValueDictionary(Object) 的函式,將 routeParameters 傳入的物件轉換成 RouteValueDictionary 物件。This method converts the object that is passed in routeParameters to a RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor.

另請參閱

GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。Gets the URL that corresponds to a set of route parameters.

public:
 System::String ^ GetRouteUrl(System::Web::Routing::RouteValueDictionary ^ routeParameters);
public string GetRouteUrl (System.Web.Routing.RouteValueDictionary routeParameters);
member this.GetRouteUrl : System.Web.Routing.RouteValueDictionary -> string
Public Function GetRouteUrl (routeParameters As RouteValueDictionary) As String

參數

routeParameters
RouteValueDictionary

路由參數。The route parameters.

傳回

對應於指定之路由參數的 URL。The URL that corresponds to the specified route parameters.

範例

下列範例示範如何呼叫這個方法,以取得具有名為 productidcategory之參數的路由 URL。The following example shows how to call this method to get the URL of a route that has parameters that are named productid and category. 這個範例假設您已建立名為 HyperLink1HyperLink 控制項。This example assumes that you have created a HyperLink control that is named HyperLink1.

HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl(  
  new RouteValueDictionary {productId="1", category="widgets"})  
HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl(  
  (new RouteValueDictionary {productId="1", category="widgets"});  

備註

提供此方法是為了方便撰寫程式碼。This method is provided for coding convenience. 這相當於呼叫 RouteCollection.GetVirtualPath(RequestContext, RouteValueDictionary) 方法。It is equivalent to calling the RouteCollection.GetVirtualPath(RequestContext, RouteValueDictionary) method.

另請參閱

GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。Gets the URL that corresponds to a set of route parameters and a route name.

public:
 System::String ^ GetRouteUrl(System::String ^ routeName, System::Object ^ routeParameters);
public string GetRouteUrl (string routeName, object routeParameters);
member this.GetRouteUrl : string * obj -> string
Public Function GetRouteUrl (routeName As String, routeParameters As Object) As String

參數

routeName
String

路由的名稱。The name of the route.

routeParameters
Object

路由參數。The route parameters.

傳回

對應於指定之路由參數及路由名稱的 URL。The URL that corresponds to the specified route parameters and route name.

範例

下列範例示範如何呼叫這個方法,以取得名為 Product 的路由 URL,並具有名為 productidcategory的參數。The following example shows how to call this method to get the URL of a route that is named Product and has parameters that are named productid and category. 這個範例假設您已建立名為 HyperLink1HyperLink 控制項。This example assumes that you have created a HyperLink control that is named HyperLink1.

HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl("Product",  
  New With {.productid = "1", .category = "widgets"})  
HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl("Product",  
  new { productid = "1", category = "widgets" });  

備註

提供此方法是為了方便撰寫程式碼。This method is provided for coding convenience. 這相當於呼叫 RouteCollection.GetVirtualPath(RequestContext, String, RouteValueDictionary) 方法。It is equivalent to calling the RouteCollection.GetVirtualPath(RequestContext, String, RouteValueDictionary) method. 這個方法會使用 RouteValueDictionary.RouteValueDictionary(Object) 的函式,將 routeParameters 傳入的物件轉換成 RouteValueDictionary 物件。This method converts the object that is passed in routeParameters to a RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor.

另請參閱

GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。Gets the URL that corresponds to a set of route parameters and a route name.

public:
 System::String ^ GetRouteUrl(System::String ^ routeName, System::Web::Routing::RouteValueDictionary ^ routeParameters);
public string GetRouteUrl (string routeName, System.Web.Routing.RouteValueDictionary routeParameters);
member this.GetRouteUrl : string * System.Web.Routing.RouteValueDictionary -> string
Public Function GetRouteUrl (routeName As String, routeParameters As RouteValueDictionary) As String

參數

routeName
String

路由的名稱。The name of the route.

routeParameters
RouteValueDictionary

路由參數。The route parameters.

傳回

對應於指定之路由參數及路由名稱的 URL。The URL that corresponds to the specified route parameters and route name.

範例

下列範例示範如何呼叫這個方法,以取得名為 Product 的路由 URL,並具有名為 productidcategory的參數。The following example shows how to call this method to get the URL of a route that is named Product and has parameters that are named productid and category. 這個範例假設您已建立名為 HyperLink1HyperLink 控制項。This example assumes that you have created a HyperLink control that is named HyperLink1.

HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl("Product",  
  new RouteValueDictionary {productId="1", category="widgets"})  
HyperLink1.NavigateUrl = HyperLink1.GetRouteUrl("Product",  
  (new RouteValueDictionary {productId="1", category="widgets"});  

備註

提供此方法是為了方便撰寫程式碼。This method is provided for coding convenience. 這相當於呼叫 RouteCollection.GetVirtualPath(RequestContext, String, RouteValueDictionary) 方法。It is equivalent to calling the RouteCollection.GetVirtualPath(RequestContext, String, RouteValueDictionary) method.

另請參閱

適用於