views:

46

answers:

3

Do the parameter names in ASP.NET MVC routes need to match those in their corresponding actions, and if so, why?

A: 

1) Yes. 2) How else would they match? The name is all you have, in both cases.

Craig Stuntz
I was thinking they might match based on position, but clearly this is not possible. I'll have to think this one through...
Ben Aston
A: 

No, not when you create your own defaultmodelbinder and/or controlleractioninvoker

Paco
No, it's a lot more complicated than that. You haven't considered the action method selector. Recall that actions can be overloaded; multiple actions can have the same name, if their args are different. Being *able* to bind the param does not mean that you *should* -- you can have multiple args of the same type. You then have to ask: Which tokens in the request (QSPs, form keys, server vars, etc) should be considered when asking if an action is valid for the request. And like I said, at that point, the name is all you have. It's the only thing which is in the route *and* in the action.
Craig Stuntz
The action method selector is in the controlleraction invoker and can be changed to not depend on the "action" value in the routevalues. I have actually done this for a complicated but useful purpose and it works.
Paco
To put this more concisely: You can, with *significant* effort, redefine "match" as meaning something other than "equals," but *don't fool yourself:* You're still matching the names, no matter how you do it.
Craig Stuntz
Yes it was significant effort. But the effort saved me manually mapping the +-1000 routes in a very large application by calling one method that resolves all the conventions to build the routes with reflection of the controllers. These conventions are significally different from the original ones in mvc. I also gained a big performance increase by using my own convention to format routes. The app can handle +- 250request/box/second and before it was 75
Paco
A: 

Yes, bacause of convention (over configuration). It's simplier and faster do develop application in that way: that's the power of ASP.NET MVC.

dario
The disadvantage is that you have to use the same conventions for every application. The conventions are based on the opinions of the creators of the mvc framework, and not on your or mine opinions. Convention over configuration is ideal, as long as the conventions are configurable and not too much opiniated. In some applications, it can be very useful to override the conventions, which is not easy, but can be done.
Paco
I think that one convertion over many applications is a way to produce software quickly with strong architecture in mind. You dont worry about configuration: Converntions give you one advangage: you need do think about WHAT, not HOW (to make the same, repeatable things).
dario