我正在尝试将参数传递给角度控制器。它不起作用。我收到此错误消息:
“无法加载模板:App / Views / CustomerDetail.html”。
我正在使用MVC和角度路由机制。
这是我的项目结构:
并且,我的路线配置文件:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Customer",
url: "Customer/{*catchall}",
defaults: new { controller = "Home", action = "Customers" });
routes.MapRoute(
name: "order",
url: "order/{*catchall}",
defaults: new { controller = "Home", action = "Orders" });
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
我的HTML5模型的角度配置:
'use strict';
var myApp = angular.module('myApp', ['ngRoute', 'appControllers']);
myApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.when('/Customer', {
templateUrl: 'App/Views/Customers.html',
controller: 'customerController'
}).
when('/Customer/:customerId', {
templateUrl: 'App/Views/CustomerDetail.html',
controller: 'customerDetailController'
}).
when('/order', {
templateUrl: 'App/Views/Orders.html',
controller: 'orderController'
}).
otherwise({
redirectTo:'/'
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
而且,我的家庭控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Customers()
{
return View();
}
public ActionResult Orders()
{
return View();
}
}
我正在尝试网址http://localhost:1458/Customer/1
我认为我在做路由机制时做错了。你能解释一下吗?我在哪里弄错了?