ASP.NET MVC is an interesting new technology that supports separating the user interface from the application logic, and the data storage from the data manipulation. When you create ASP.NET MVC applications, the old ASP.NET style of accepting input from the user is no longer the best option. Furthermore, you will also need to learn how to dynamically accept input from the user.
Assume you want to implement a method to process an URL, such as "/products/edit/NNN", where NNN would be an ID number of a product. As you learned in my earlier article, "ASP.NET MVC 101," you would start by writing a public method named Edit in the ProductsController class of your application.
However, how would you be able to retrieve the product ID that the user wants to edit? In regular ASP.NET, you would access the Request object and find the information you want. But in ASP.NET MVC, you have an surprisingly easy alternative. All you need to do is declare the Edit method so that it accepts a parameter with the name "Id", and you are done!
You might wonder how this works. To find the answer, you need to recall the declaration of the default route you saw earlier. Remember how it contained the ID parameter as the third parameter? If you declare a controller method with this parameter, you will automatically get the value as a parameter to your controller when the user accesses the URL.
The routing system in MVC applications looks for particular controller methods that have parameters that match the route parameters. The default route is "{controller}/{action}/{id}", and given the request URL of "/products/edit/123", the system looks for an Edit method that takes parameter with the name "ID" (case is not important). That is, the naming of parameters is important, but so is also typing.
Read the Rest of this Article at Developer.com