WebApi路由没有传递值

Ian*_*ink 0 asp.net asp.net-mvc asp.net-mvc-4 asp.net-web-api

我试图将值传递给Web Api中的控制器/操作,但它没有找到它.

我的路线图:

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
Run Code Online (Sandbox Code Playgroud)

我的ApiController:

    [HttpGet]
    public string MyThing()
    {
        return "thing";
    }

    [HttpGet]
    public string MyStuff(int myid)
    {
        return "something " + myid;
    }
Run Code Online (Sandbox Code Playgroud)

通过RestSharp我的REST调用:

var request = new RestRequest { Resource = "api/values/MyStuff/555", Method = Method.GET };
Run Code Online (Sandbox Code Playgroud)

如果我称MyThing()它有效.似乎问题在于传递id值.

Kir*_*lla 6

将参数名称从"myid"修改为"id"

[HttpGet]
public string MyStuff(int **id**)
Run Code Online (Sandbox Code Playgroud)