Is there any way to get truly restful routing working in MVC, just like the rails dudes have? I 'm talking about nested urls like /bands/metallica/albums/killemall/track/4
The only library that I found to be useful is Steve Hodgkiss' Restful routing. It seems though a bit risky to base my whole project's routing on this guy's pet-project.
What say you MVC veterans?
ASP.NET MVC is one such framework that provides an inherently RESTful model for building XHTML-based services.
For controllers, the above configuration specifies a default routing convention, which is the fairly standard {controller}/{action}/{id?} pattern that's been recommended since the first versions of ASP.NET MVC.
There are two types of routing (after the introduction of ASP.NET MVC 5). Convention based routing - to define this type of routing, we call MapRoute method and set its unique name, url pattern and specify some default values.
The RegisterRoutes() method creates the route table. The default route table contains a single route (named Default). The Default route maps the first segment of a URL to a controller name, the second segment of a URL to a controller action, and the third segment to a parameter named id.
Sure:
routes.MapRoute("IwannaBeLikeTheCoolRailsKids",
"bands/{bandName}/albums/{albumName}/tracks/{trackNumber}",
new { controller = "Bands",
action = "ByTrack"
});
Then in your controller:
public ActionResult ByTrack(string bandName, string albumName, int trackNumber)
Easy peasie.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With