Can somebody help with this? I have this controller:
public class CbpOutcomeController : ApiController
{
// POST /api/CbpOutcome/1/
public HttpResponseMessage PostCreateCbpOutcome(CbpOutcome co)
{
... snip ...
return resp_msg;
}
}
And this route:
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 }
);
}
}
And when I make the POST to http://localhost:2515/api/CpbOutcome, with this JSON structure:
{ "Id":0, "Description":"This is a description", "DisplayOrder": 3,
"ModifiedBy":"Somebody's name here", "Cbp": { "Id": 163 }}
I get this message:
No type was found that matches the controller named 'CpbOutcome'.
—Edit—
See the spelling of the your API class.
Then see the spelling of your URL:
Notice the Cbp and the Cpb
—End Edit—
API Controller URL should reside inside the
WebApiConfig.csfile.Not inside the
RouteConfig.csfileAnalyse the default template provide with VS2012 for a Web API project and you will see it.