我有一个asp web API项目和相关的AngularJS项目
我知道如果我想给Angular外观,我应该致电index.html
所以
index.html
文件作为默认页面调用? RouteConfig
:
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 }
);
}
WebApiConfig
的艺术:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
答案 0 :(得分:1)
如果你想使用angularjs路由设置你的routeConfig如下:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "App",
url: "App/{*catchall}",
defaults: new { controller = "App", action = "Index" });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "App", action = "Index", id = UrlParameter.Optional }
);
在index.cshtml视图中,您需要在HTML标记上定义您的应用,并添加您的ng-view指令:
<html ng-app="appModule">
<div ng-view>
</div>
</html>
这将让应用程序继续运行。确保在index.cshtml文件中包含所有.js文件。
在app(mvc)控制器中,我们为角应用程序引导一些数据。你可以随心所欲地做到这一点。