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值.
将参数名称从"myid"修改为"id"
[HttpGet]
public string MyStuff(int **id**)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
154 次 |
| 最近记录: |