How can my route use optional parameters in the middle of the URL using ASP MVC3?

I think you probably need two separate routes for this.

Up vote 2 down vote favorite share g+ share fb share tw.

I would like my URLs to use the convention: /{controller}/{id}/{action} rather than /{controller}/{action}/{id} I tried setting up a route as follows: routes. MapRoute( "Campaign", "{controller}/{action}/{id}", new { controller = "Campaign", action = "Index", id = UrlParameter. Optional } ); But this doesn't work because I am unable to make the id parameter optional.

The following URLs do work: /campaign/1234/dashboard /campaign/1234/edit /campaign/1234/delete But these URLs do not: /campaign/create /campaign/indexempty MVC just calls Index for both. What am I doing wrong? Asp.

Net-mvc-3 link|improve this question asked Nov 29 '11 at 16:23parleer626 100% accept rate.

I think you probably need two separate routes for this. Routes. MapRoute( "CampaignDetail", "{controller}/{id}/{action}", new { controller = "Campaign", action = "Index" } ); routes.

MapRoute( "Campaign", "{controller}/{action}", new { controller = "Campaign", action = "Index" } ).

That worked! Slight modification to your code--I named the first route "CampaignDetail" so that it wouldn't conflict with the second route. – parleer Nov 29 '11 at 16:59 Oh, I missed that.

I'm glad it helped. – John Allers Nov 29 '11 at 17:40 One more thing--Having {controller}/{id}/{action} interfered with my default route. I was able to fix this by explicitly using the word campaign in my url.

I.e. Campaign/{id}/{action}. – parleer Nov 30 '11 at 3:52.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send