我开始使用MVC4 Web API项目,我有多种HttpPost方法的控制器.控制器如下所示:
调节器
public class VTRoutingController : ApiController
{
[HttpPost]
public MyResult Route(MyRequestTemplate routingRequestTemplate)
{
return null;
}
[HttpPost]
public MyResult TSPRoute(MyRequestTemplate routingRequestTemplate)
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
这里MyRequestTemplate表示负责处理通过请求的Json的模板类.
错误:
当我让使用招为请求http://localhost:52370/api/VTRouting/TSPRoute或http://localhost:52370/api/VTRouting/Route 我得到一个错误:
找到了与请求匹配的多个操作
如果我删除上述方法之一,它工作正常.
Global.asax中
我已经尝试修改默认路由表global.asax,但我仍然收到错误,我认为我在global.asax中定义路由时遇到问题.这是我在global.asax中所做的.
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapHttpRoute(
name: "MyTSPRoute",
routeTemplate: "api/VTRouting/TSPRoute",
defaults: new { }
);
routes.MapHttpRoute(
name: "MyRoute",
routeTemplate: "api/VTRouting/Route",
defaults: new { action="Route" }
);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用POST在Fiddler中发出请求,在RequestBody中为MyRequestTemplate传递json.