【发布时间】:2016-04-14 11:06:04
【问题描述】:
我有这个控制器,我想不通,为什么name参数为空
public class DeviceController : ApiController
{
[HttpPost]
public void Select([FromBody]string name)
{
//problem: name is always null
}
}
这是我的路线图:
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}"
);
appBuilder.UseWebApi(config);
}
这是我的要求:
POST http://localhost:9000/api/device/Select HTTP/1.2
User-Agent: Fiddler
Host: localhost:9000
Content-Length: 16
Content-Type: application/json
{'name':'hello'}
我还尝试将正文更改为纯字符串:hello。
POST http://localhost:9000/api/device/Select HTTP/1.2
User-Agent: Fiddler
Host: localhost:9000
Content-Length: 5
Content-Type: application/json
hello
请求返回 204 是可以的,但参数永远不会映射到发布的值。
*我正在使用自托管的 owin 服务。
【问题讨论】:
标签: c# asp.net-web-api asp.net-mvc-routing owin model-binding