Quantcast
Channel: Developing Code, Connecting Industry » Point2 – Technical
Viewing all articles
Browse latest Browse all 10

Article 4

$
0
0

In one of the MVC3 apps i’ve been working on we decided to make sure that all of the urls specify information in a restful fashion, that is they are all directly in the path(route), nothing in request parameters.  Everything was going smoothly until we hit our first action where parameters are optional.

Lets look at this theoretical route table:

"{controller}/{action}/{year}/team/{teamId}/car/{carId}/track/{trackId}"
"{controller}/{action}/{year}/track/{trackId}/car/{carId}"
"{controller}/{action}/{year}/car/{carId}"

So you could imagine that we would have different urls that apply to these routes like:

http://www.racingstats.com/yearlySummary/Nascar/2011/team/AmsOil/car/12 
http://www.racingstats.com/yearlySummary/Nascar/2011/track/taladega/car/12 
http://www.racingstats.com/yearlySummary/Nascar/2011/car/12 

The problem is that this url pattern isn’t gracefully handled out of the box with mvc3.  If you tried to hit one you would be greated with a nice exception:

The current request for action ‘Nascar’ on controller type ‘YearlySummaryController’ is ambiguous between the following action methods:….

see the solution here…

 



Viewing all articles
Browse latest Browse all 10

Trending Articles