Upgrading an rc to rtm web api project
Default parameter binding for simple type parameters is now [FromUri]: In previous releases of ASP.NET Web API the default parameter binding for simple type parameters used model binding. The default parameter binding for simple type parameters is now [FromUri].
I believe is the change that is causing me greif.
Well now I’m not so sure. StrathWeb seems to make me thing it should just work as is.
Given this endpoint
[HttpGet]
public HttpResponseMessage Method(string a, string b)
{
...
}
I generate a url on the client using
@Url.RouteUrl("route", new { httproute = "", controller = "Controller", version = "1" })">
to get it to generate the url for this route.
routes.MapHttpRoute(
name: "route",
routeTemplate: "api/v{version}/{controller}/Method",
defaults: new
{
action = "Method",
controller = "Controller",
version = "1"
});
It creates the url fine. The urls looks like
.../api/v1/Controller/Method?optional=z
.../api/v1/Controller/Method?a=x&b=y&optional=z
It throws a 404 when requested. If I remove the parameters a and b in the api controller then it enters the method just fine.
What is the correct way to make these bind?
if you need ‘a’ and ‘b’ to be optional, then you would need to make them optional parameters:
public HttpResponseMessage Method(string a = null, string b = null)