二更:
之前的分析不正確。
在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兩個接口的參數名完全相同。
修改方法:區分兩個接口的參數名(如下圖)。(修改參數類型試過是沒用的)