在 MVC4 Web API 项目中具有以下“itemtypelist”路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "itemtypelist",
url: "{controller}/list/{itemtype}/{searchtext}",
defaults: new { controller = "home", action = "list", itemtype = (string)null, searchtext = (string)null }
);
}
旨在映射到以下控制器操作
[AcceptVerbs("GET", "POST")]
public IEnumerable<Repository.ViewModel.Brand> List(string itemType, string searchText)
和网址
/api/brand/list/mytype/mysearchtext
但是,该 URL 返回 404 消息。此路由和控制器操作在网站项目中有效,但在 Web API 项目中无效。MVC4 Web API 项目中有什么不同会导致找不到操作?