routing in asp.net mvc Options

Now it’s time for you to employ our have routes. The best route will take a controller and an motion without any defaults or further parameters.

Within our illustration, we want to limit the id parameter to just accept only integer values. So, we must modify the MapControllerRoute Middleware Component as follows. As you may see, as A part of the sample, we specify the id parameter to simply accept int values only (pattern: “ controller / action / id:int ”).

You might guess the route values controller = Household, motion = Index will be more than enough to produce a URL working with blog, and the result can be /blog?action=Index&controller=Residence.

With the above variations in position, run the applying and navigate to the particular URLs, and you may get the information as anticipated.

The 1st two controllers are users of regions, and only match when their respective region identify is furnished by the realm route worth. The third controller just isn't a member of any place, and might only match when no value for region is provided by routing.

Routing tries to make use of the values in ambient values to fill in facts that was not presented when making a URL. Look at a route just like a / b / c / d with ambient values a = Alice, b = Bob, c = Carol, d = David :

Using the preceding controller definition and route template, the HomeController.Index action is run for the following URL paths:

The following instance configures MVC to make use of the default conventional route and a place route for a location named Blog:

Common routing only matches a mix of motion and controller which are defined with the app. This is intended to simplify situations wherever common routes overlap.

Token replacement happens as the final phase of developing the attribute routes. The previous case in point behaves similar to the following code:

Actions are possibly routing in asp.net mvc conventionally routed or attribute routed. Placing a route about the controller or the action causes it to be attribute routed.

Note: The route title ought to be unique over the full application. Route identify can’t be duplicated.

If your app is using the default conventional route, the worth of the url variable is the URL route string /UrlGeneration/Location. This URL path is created by routing by combining:

Placing multiple route attributes about the controller ensures that every one combines with Each and every with the route characteristics on the action approaches:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Comments on “routing in asp.net mvc Options”

Leave a Reply

Gravatar