Is there someone who could shed a light on why ambiguous methods are not allowed in ASP.Net MVC?
I updated my question just to clarify it (using Carson63000 example from his answer), the question itself remains the same.
So, lets say we have the following action
/article/list/sport
which calls
public ActionResult List(string category) { }
and want to be able to have the following action as well:
/article/list/sport/20110904
which we would like to call accompanying method
public ActionResult List(string category, DateTime date) { }
Currently the framework throws an AmbiguousMatchException
since it found two methods called List. That's the only reason for throwing the exception, that more than one method with was found that matches the actions name.
After the framework has figured out what method to use and decided that it is not ambigious, it will then try to map the supplied data from the request to the parameters of the method. Why not do this the other way around? First get all applicable methods, and then try to find the best fit by mapping parameters.
If ambiguous methods where allowed, I think the following is still possible to do.
Given that /article/list/sport
uses the route /{controller}/{action}/{category}
and that /article/list/sport/20110903
uses the route /{controller}/{action}/{category}/{date}
it would then still be possible to map data for url /article/list/sport?date=20110903
since it will match the route for just category, but can still map the data for method public ActionResult List(string category, DateTime date) { }
.
At the moment I fail to see the reason for not allowing ambiguous methods from a design perspective. The only thing I can think of myself is that it will slow down the framework too much, and therefor the current solution is the more logical one. Or am I missing another point here?