本文介绍了为什么这不是空MVC Web应用程序加载ANGULAR view1.cshtml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习角。我正在看一个2岁的视频,我想使用路由的概念和使用view1.CShtml(请记住,它的CSHTML而不是HTML格式,而在视频中,他使用HTML)。

奇怪的浏览路径开始为

我也觉得〜查看/ View1.cshtml上违背了部分/视图1在视频演示了(够我有它在浏览文件夹中博会)。现在,我不明白这是什么〜当我有这样的演示类似的目录结构。

此外,可悲的是,厂景没有加载:(什么问题呢?当然,他使用一个模块和控制器,但我想也可以使用相关的模块,我自己的学习....这里有什么问题吗?


    
        
     
  
    

  angular.module('应用',['myFirstApp'])。控制器(冷杉,函数($范围){
        $ scope.Customers = [
      {名称:'Kiam,城市:洛杉矶},
      {名称:'硒',城市:洛杉矶拉斯维加斯'}
        ]
    })。配置(函数($ routeProvider){
        $ routeProvider
        。当('/视图1',
        {
            控制器:杉树,
            templateUrl:'〜查看/ View1.cshtml
        })
        。当('/视图2',
        {
            控制器:第一,
            templateUrl:'〜查看/ View2.cshtml
        })
        不然的话({redirectTo:'/视图1'});
    });
    变种临时= angular.module('myFirstApp',[]);    变种controllerCollection = {};
    controllerCollection.First =功能($范围){
        $ scope.Customers = [
      {名称:'西塔',城市:洛杉矶},
      {名称:'拉姆',城市:洛杉矶拉斯维加斯},        ]
    };    temp.controller(controllerCollection);


解决方案

您可以尝试这样的。当('/视图1',{控制器:杉树,templateUrl:'/ MyViews /视图1'}),这是不够。同时检查配置的路由路径添加与否的路线。如果您使用的是$ routeprovider它会自动生成在Global.asax中的路由路径。

要显示无需额外指定为视图页面.cshtml。

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).

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.

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);
解决方案

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.

No need to specify additionally the .cshtml for the view page to be displayed.

这篇关于为什么这不是空MVC Web应用程序加载ANGULAR view1.cshtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 09:18