二更:
之前的分析不正确。
在webapiconfig里 路径controller后面加上{action}即可。这是MVC4的解决办法。
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
//config.EnableQuerySupport();
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
}
}
MVC5可以通过Route[]解决。有例子了再来添加。
api有两个Post方法的接口,写了个测试工具调它。刚开始还正常运行,后面就一直报错500。
报错原因:ProductCheck和ProductSave两个接口的参数名完全相同。
修改方法:区分两个接口的参数名(如下图)。(修改参数类型试过是没用的)