ASP.NET MVC Preview 3 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 17
This would pass appropriate "language",
"locale", and "category" parameters to a
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 18
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 3 also supports wildcard route rules
(these were also in Preview 2). For example, you can indicate in a rule
to pass all remaining URI content on as a named parameter to an action method:
Figure 19
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 are very useful to look at if you are
building a blogging, wiki, cms or other content based system.