C# 将大多数MVC操作定向到Web API控制器
我已经用一个Web API控制器构建了一个MVC项目。我没有使用C# 将大多数MVC操作定向到Web API控制器,c#,asp.net-mvc,asp.net-web-api,asp.net-web-api-routing,C#,Asp.net Mvc,Asp.net Web Api,Asp.net Web Api Routing,我已经用一个Web API控制器构建了一个MVC项目。我没有使用POST,GET方法,而是将路由配置为在API控制器中使用操作 这是我的路由器配置: var reportRoute = routes.MapHttpRoute(name: "Report", routeTemplate: "api/Report/{controller}/{action}"); reportRoute.AddRouteToken("Namespaces",
POST
,GET
方法,而是将路由配置为在API控制器中使用操作
这是我的路由器配置:
var reportRoute = routes.MapHttpRoute(name: "Report",
routeTemplate: "api/Report/{controller}/{action}");
reportRoute.AddRouteToken("Namespaces", new string[] { "Fanex.Athena.Api.Report" });
reportRoute.RouteHandler = new MyHttpControllerRouteHandler();
这是我的控制器:
[HttpPost]
public dynamic MatchWlMatchBetType(BetListMetaModel metaModel)
{
var uspKey = IsRacing(metaModel.BetType)
? "xxxxx"
: "xxxaaa";
return GetBetListResult(metaModel, uspKey);
}
[HttpPost]
public dynamic MatchWlOutright(BetListMetaModel metaModel)
{
const string uspKey = "xxxx";
return GetBetListResult(metaModel, uspKey);
}
我不知道这个代码是好是坏。我是否正确使用Web API控制器?为什么您认为它不好?我认为这没什么问题。在Web Api中使用动词是一种建议的方法,而不是一种规则。不确定这是否是代码复查的好问题。@Kev感谢您的关注=)