问题描述
我正在学习 Angular.我正在观看一个 2 年前的视频,我正在尝试使用路线概念并在 view1.CShtml 中使用(请记住,它的 CShtml 而不是 html,而在视频中,他使用的是 html).
I am learning Angular. I am watching a 2 years old video, and I am trying to use route concept and using in view1.CShtml (Remember, its CShtml and not html, while in the video, he uses html).
我还发现 Views 路径以 ~Views/View1.cshtml 开头(我在 Views 文件夹中有它)很奇怪,这与视频演示器所在的 Partial/View1 相反.现在,当我有类似演示程序的目录结构时,我不明白这个~"是什么.
I also find it wierd that Views path starts as ~Views/View1.cshtml (Fair enough I have it in Views folder) on contrary to Partial/View1 where the video demonstrator has. Now, I do not understand what is this "~" for when I have similar directory structure like demonstrator.
另外,遗憾的是,view1 没有加载:( 有什么问题?当然他使用单个模块和控制器,但我也尝试使用依赖模块来进行我自己的学习......这里有什么问题?
Also, sadly, the view1 is not loading :( What is the problem? Of course he use single module and controller, but I am trying to use dependent module also for my own learning....What's the problem here?
angular.module('App', ['myFirstApp']).controller('Fir', function ($scope) {
$scope.Customers = [
{ name: 'Kiam', city: 'Los Angeles' },
{ name: 'Se', city: 'Los Vegas' }
]
}).config(function ($routeProvider) {
$routeProvider
.when('/View1',
{
controller: 'Fir',
templateUrl: '~Views/View1.cshtml'
})
.when('/View2',
{
controller: 'First',
templateUrl: '~Views/View2.cshtml'
})
.otherwise({ redirectTo: '/View1' });
});
var temp = angular.module('myFirstApp', []);
var controllerCollection = {};
controllerCollection.First = function ($scope) {
$scope.Customers = [
{ name: 'Sita', city: 'Los Angeles' },
{ name: 'Ram', city: 'Los Vegas' },
]
};
temp.controller(controllerCollection);
推荐答案
你可以这样试试 .when('/View1', { controller: 'Fir', templateUrl: '/MyViews/View1'}),就够了.并检查路由配置是否添加了路由路径.如果您使用 $routeprovider,它将自动在 global.asax 中生成路由路径.
you could try like this .when('/View1', { controller: 'Fir', templateUrl: '/MyViews/View1'}), it's enough. and also check the route config the routing path is added or not. If you are using the $routeprovider it will automatically generated the routing path in global.asax.
无需另外指定要显示的视图页面的 .cshtml.
No need to specify additionally the .cshtml for the view page to be displayed.
这篇关于为什么这不在 MVC 空 Web 应用程序 ANGULAR 中加载 view1.cshtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!