Compartilhar via


RouteCollectionExtensions.MapRoute Method (RouteCollection, String, String, Object, Object, String[])

Maps the specified URL route and sets default route values, constraints, and namespaces.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function MapRoute ( _
    routes As RouteCollection, _
    name As String, _
    url As String, _
    defaults As Object, _
    constraints As Object, _
    namespaces As String() _
) As Route
public static Route MapRoute(
    this RouteCollection routes,
    string name,
    string url,
    Object defaults,
    Object constraints,
    string[] namespaces
)
[ExtensionAttribute]
public:
static Route^ MapRoute(
    RouteCollection^ routes, 
    String^ name, 
    String^ url, 
    Object^ defaults, 
    Object^ constraints, 
    array<String^>^ namespaces
)

Parameters

  • defaults
    Type: System.Object
    An object that contains default route values.
  • constraints
    Type: System.Object
    A set of expressions that specify values for the url parameter.
  • namespaces
    Type: System.String[]
    A set of namespaces for the application.

Return Value

Type: System.Web.Routing.Route
A reference to the mapped route.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type RouteCollection. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

Exception Condition
ArgumentNullException

The routes or url parameter is null reference (Nothing in Visual Basic).

See Also

Reference

RouteCollectionExtensions Class

MapRoute Overload

System.Web.Mvc Namespace