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。Gets the URL that corresponds to a set of route parameters and a route name.

GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 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。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。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.

另请参阅

适用于