默认的 MVC4 应用程序将带有一个RouteConfig
看起来像这样的类:
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
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 }
);
}
我的问题是,为什么MapHttpRoute
?这是为新的 WebApi 功能设置路由,但我没有选择 WebApi 项目,只是一个普通的 MVC4 项目。普通的 MVC4 项目中似乎不需要 WebApi。