Share via


IRouteValueProvider Interface

Definition

A metadata interface which specifies a route value which is required for the action selector to choose an action. When applied to an action using attribute routing, the route value will be added to the Values when the action is selected.

When an IRouteValueProvider is used to provide a new route value to an action, all actions in the application must also have a value associated with that key, or have an implicit value of null. See remarks for more details.

public interface class IRouteValueProvider
public interface IRouteValueProvider
type IRouteValueProvider = interface
Public Interface IRouteValueProvider
Derived

Remarks

The typical scheme for action selection in an MVC application is that an action will require the matching values for its ControllerName and ActionName

For an action like MyApp.Controllers.HomeController.Index(), in order to be selected, the Values must contain the values { "action": "Index", "controller": "Home" }

If areas are in use in the application (see AreaAttribute which implements IRouteValueProvider) then all actions are consider either in an area by having a non-null area value (specified by AreaAttribute or another IRouteValueProvider) or are considered 'outside' of areas by having the value null.

Consider an application with two controllers, each with an Index action method: - MyApp.Controllers.HomeController.Index() - MyApp.Areas.Blog.Controllers.HomeController.Index() where MyApp.Areas.Blog.Controllers.HomeController has an area attribute [Area("Blog")].

For Values like: { "action": "Index", "controller": "Home" }

MyApp.Controllers.HomeController.Index() will be selected. MyApp.Area.Blog.Controllers.HomeController.Index() is not considered eligible because the Values does not contain the value 'Blog' for 'area'.

For Values like: { "area": "Blog", "action": "Index", "controller": "Home" }

MyApp.Area.Blog.Controllers.HomeController.Index() will be selected. MyApp.Controllers.HomeController.Index() is not considered eligible because the route values contain a value for 'area'. MyApp.Controllers.HomeController.Index() cannot match any value for 'area' other than null.

Properties

RouteKey

The route value key.

RouteValue

The route value. If null or empty, requires the route value associated with RouteKey to be missing or null.

Applies to