I’d like to send multiple parameters to an action in ASP.NET MVC. I’d also like the URL to look like this:
http://example.com/products/item/2
instead of:
http://example.com/products/item.aspx?id=2
I’d like to do the same for sender as well, here’s the current URL:
http://example.com/products/item.aspx?id=2&sender=1
How do I accomplish both with C# in ASP.NET MVC?
If you’re ok with passing things in the query string, it’s quite easy. Simply change the Action method to take an additional parameter with a matching name:
Would become:
ASP.NET MVC will do the work of wiring everything up for you.
If you want a clean looking URL, you simply need to add the new route to Global.asax.cs: