【发布时间】:2014-06-05 19:35:10
【问题描述】:
在控制器中,我有这样的方法:
public class FooController : ApiController
{
[HttpPost]
public HttpResponseMessage ApplySomething(int id)
{
...
}
}
当我执行 .../Foo/ApplySomething/ 之类的 POST 请求并将 id=1 作为 POST 值传递时,出现错误:
{
Message: "No HTTP resource was found that matches the request URI '.../Foo/ApplySomething/'."
MessageDetail: "No action was found on the controller 'Foo' that matches the name 'ApplySomething'."
}
但是当我将 URL 更改为具有 ID(如 .../Foo/ApplySomething/1)时,它可以工作,但从 URL 获取值,而不是从 POST 值。
我做错了什么?
【问题讨论】:
-
/Foo/ApplySomething?id=1 有效吗?
-
是的,/Foo/ApplySomething?id=1 和 /Foo/ApplySomething/1 的工作方式相同。
标签: c# .net asp.net-mvc restful-url