Reputation: 22392
The standard route for the MVC Web API is {controller}/{id}. However I'd like to name my variables more descriptively then just 'id'. To do this though it would make more sense to me if I could map routes directly to methods as the WCF Web API worked. Is there a way to do this with MVC or is there is a more MVCish way of routing but still maintaining unique identifiable placeholders for each method?. Or am I stuck just naming all my parameters id?
[WebGet(UriTempalte="{controller}/{email}"]
public string GetEmail(string email)
Instead of:
public string GetEmail(string id)
Upvotes: 1
Views: 350
Reputation: 10532
If you name it email
- then create a separate Route in Global.asax.cs naming your parameter accordingly, i.e. {controller}\{email}
. In MVC routes you only have a very short list of MVC-specific keywords - {controller}, {action}, {area} etc. All the other parameters are passed to corresponding action parameters (if they are present in your action method signature of course).
Upvotes: 2
Reputation: 9922
Doesn't routes.MapRoute("getemail/{email}", new { controller = "EmailGetter", action = "GetEmail" })
suffice you?
Upvotes: 1