In my web app. i want to setup a route like this:
/document/quality/index /document/general/index /document/quality/detail/[id] /document/general/detail/[id]
As you can see i have two kind of documents: general and quality. What is the best way to set this up in my global.asax file? I tried the following, but i don’t get it work:
routes.MapRoute( 'QualityDocument', 'Document/Quality/{action}/{id}', new { controller = 'Document', action='Index', id= ''} ); routes.MapRoute( 'GeneralDocument', 'Document/General/{action}/{id}', new { controller = 'Document', action = 'Index', id = '' } ); routes.MapRoute( 'Default', // Route name '{controller}/{action}/{id}', // URL with parameters new { controller = 'Home', action = 'Index', id = '' } // Parameter defaults );
EDIT
I have it working right now, but when i change the action=” in my asax file it doesn’t work anymore:
Global.asax:
routes.MapRoute( 'GeneralDocument', 'Document/General/{action}/{id}', new { controller = 'Document', action = 'blaat', id = '' } );
DocumentController:
public void blaat(int? id) { Response.Write('algemeen'); // return View(); }
Now i get the Resource not found error. But when I use index instead of blaat it is working. How come?
you should be able to just prefix the route with ‘Document’ and then set the defaults like:
remember with routing you want to be completely defining! when setting out the route. dont let those unexpected routes through 😀
Check out Scott Hanselman presentation at MIX very funny and your pick up some great tips!
http://www.hanselman.com/blog/Mix09FirstHalfRollupAndSessionVideos.aspx