Problems to be Solved
1: create a more concise/Product/Details/1 URL
| Valid route definitions |
Examples of matching URL |
| {Controller}/{action}/{id} |
/Products/Details/1 |
| {Controller}/{action}/{id} |
/Products/1 |
| {Controller}/{action}/{id}. {Format} |
/Products/Show/1.xml |
"/Products/Details/1" is the route for viewing the Details method of the object by default in MVC development. What needs to be implemented is a more concise url representation, such as "/Products/1 ", returns the same result as "/Products/Details/1. This process is simple. You only need to add a new routing rule to the Global. asax file, but remember to add it before the default route.
2: Create an API for/Product/Show/1. xml
To implement the xml access API, you must first create an abstract class to process the routes of returned results and the serialization of xml results. Here the class library of MVC Contrib is used, you can go to MVC Contrib Code Plex to download and add references. See return new XMLResult in the code.
The Code is as follows:
Finally, you need to add the corresponding return type to the corresponding Action. Here is Show. See
The actual effect is as follows: