问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/1669147/asp-net-mvc-and-restful-routing-rails-style-is-it-possible