ASP.NET MVC Source Refresh Preview
page 7 of 9
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 37732/ 78

Other URL Route Mapping Features

This week's MVC source drop also supports a bunch of new URL route mapping features.  You can now include "-", ".", ";" or any other characters you want as part of your route rules.

For example, using a "-" separator you can now parse the language and locale values from your URLs separately using a rule like below:

Figure 18

This would pass appropriate "language", "locale", and "category" parameters to the ProductsController.Browse action method when invoked:

URL Route Rule

Example URL

Parameters Passed to Action method

{language}-{locale}/products/

browse/{category}

/en-us/products/

browse/food

language=en, locale=us,

category=food

 

/en-uk/products

/browse/food

language=en, locale=uk,

category=food

Or you can use the "." file extension type at the end of a URL to determine whether to render back the result in either a XML or HTML format:

Figure 19

This would pass both "category" and a "format" parameters to the ProductsController.Browse action method when invoked:

URL Route Rule

Example URL

Parameters Passed to Action method

products/browse/{category}.{format}

/products/browse/food.xml

category=food, format=xml

 

/products/browse/food.html

category=food, format=html

ASP.NET MVC Preview 2 introduced wildcard route rules.  For example, you can indicate in a rule to pass all remaining URI content on as a named parameter to an action method:

Figure 20

This would pass a "contentUrl" parameter to the WikiController.DisplayPage action method when invoked:

URL Route Rule

Example URL

Parameters Passed to Action method

Wiki/Pages/{*contentUrl}

/Wiki/Pages/People/Scott

contentUrl="People/Scott"

 

/Wiki/Pages/Countries/UK

contentUrl="Countries/UK"

These wildcard routes continue to work fine with this week's preview - and are very useful to look at if you are building a blogging, wiki, cms or other content based system.

Note that in addition to using the new routing system for ASP.NET MVC scenarios, we are also now using the same routing system within ASP.NET Dynamic Data (which uses ASP.NET Web Forms).


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-25 10:44:56 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search