我创建了一个 WebApi 项目,它有多个 WebApi 控制器。根据我的要求,我必须在我的 WebApi 项目中添加一个 MVC 控制器。我的客户端代码正在向该 MVC 控制器发出 ajax 请求{ControllerName/ActionMethodName}
。我的global.asax
文件中有多个路线:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapHttpRoute(
name: "ActionRoute",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
下面是我的ReportServiceBaseController
:
protected virtual ReportServiceBase CreateReportService();
[HttpPost]
public JsonResult LoadDocumentInfo(LoadDocumentInfoRequest request);
[HttpPost]
public JsonResult LoadDocumentMapInfo(LoadDocumentMapInfoRequest request);
[HttpPost]
public JsonResult LoadDocumentMapInfoFull(LoadDocumentMapInfoFullRequest request);
[HttpPost]
public JsonResult LoadPageInfo(LoadPageInfoRequest request);
我在控制器中继承该ReportService
控制器:
public class ReportServiceController : ReportServiceBaseController
{
protected override PerpetuumSoft.Reporting.WebViewer.Server.ReportServiceBase CreateReportService()
{
return new ServiceClass();
}
}
发出请求的客户端 URL:
"http://" + 主机名 + "/ReportService/LoadDocumentInfo"
我认为 WebApi 路由正在抑制 MVC 控制器路由。如何将 MVC 控制器路由与 WebApi 路由分开?