有人可以帮忙吗?我有这个控制器:
public class CbpOutcomeController : ApiController
{
// POST /api/CbpOutcome/1/
public HttpResponseMessage PostCreateCbpOutcome(CbpOutcome co)
{
... snip ...
return resp_msg;
}
}
这条路线:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"HubProfilePostRoute", // Route name
"hub/{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
routes.MapHttpRoute(
name: "ProfileByRegionApi",
routeTemplate: "api/{controller}/Region/{region_name}"
);
routes.MapHttpRoute(
name: "ProfileByGlobalPriorityApi",
routeTemplate: "api/{controller}/GlobalPriority/{priority_name}"
);
routes.MapHttpRoute(
name: "ApiRoute",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
当我使用此JSON结构制作POST
到http://localhost:2515/api/CpbOutcome
时:
{ "Id":0, "Description":"This is a description", "DisplayOrder": 3,
"ModifiedBy":"Somebody's name here", "Cbp": { "Id": 163 }}
我收到此消息:
No type was found that matches the controller named 'CpbOutcome'.
答案 0 :(得分:5)
--- 修改强> ---
查看API类的拼写。
public class CbpOutcomeController : ApiController
然后查看您网址的拼写:
http://localhost:2515/api/CpbOutcome
注意Cbp和Cpb
--- 结束编辑 ---
API控制器URL应位于WebApiConfig.cs
文件中。
不在RouteConfig.cs
文件
为Web API项目分析VS2012提供的默认模板,您将看到它。