如何将ng-view切换到普通页面

时间:2016-09-12 12:02:20

标签: angularjs routing angular-routing ng-view

enter image description here

见图片 => Layout1母版页,其中包含ng-view,其中我使用了角度路由。

当我尝试呼叫登录页面时,

=> Layout2 login.cshml页面       http://localhost:1395/admin/home/Login

这个登录页面包含在我不想要的ng-view中 它的不同页面总共有Login.cshtml

我把这个页面称为

   <a href="admin/home/login">Log out</a> 

当我在http://localhost:1395/admin/home/Login地址栏中直接尝试网址时 它工作得很好看图像

enter image description here

但是我尝试从主面板到登录页面显示错误看到第一张图片

示例代码

master.cshtml

  <html>
 <body>
 <div>Layout 1</div>
 <div ng-view></div>
 </body>
 </html>

contact.html

 <div ng-controller="contactcontroller">
 Contact Page
 </div>

help.html

 <div ng-controller="helpcontroller">
 Help Page
</div>

路由代码

      var app = angular.module("myApp", ["ngRoute"]);
      app.config(function($routeProvider) {
    $routeProvider
   .when("/admin/home/contact", {
    templateUrl : "contact.html",
    controller: "contactcontroller"
  })
   .when("/admin/home/help", {
    templateUrl : "help.html",
    controller:   "helpcontroller"
 })    
});

Login.cshtml

 <html>
  <body>
  <div>Layout 2</div>
  ///Login code
</body>
</html>

当我在ng-view中调用此url admin / home / help和admin / home / contact页面时,但是当我调用admin / home / login时,我不希望在ng-view中包含此包含它是单独的页眉和页脚。我想把电话作为单独的页面

提前致谢

1 个答案:

答案 0 :(得分:0)

很难理解这一点,但我会小心翼翼地回答这个问题。

你的问题可能与angularjs 无关,在我看来,你可能正在使用ASP.NET MVC并且你的Login操作是在主布局中呈现的。基本上,您需要在没有模板的情况下呈现页面。在那里查看此问题和答案:Razor View Without Layout

我还要指出,angular用于单页面应用程序,并且很难混合使用角度和ASP.NET MVC路由。您应该决定使用哪种路由。当然,您可以在每个页面中使用.NET并初始化角度,但我不建议这样做。如果可以,请以角度构建所有页面,然后使用ASP.NET Web API作为后端。

使用路由并指定控制器时,也不需要使用ng-controller属性。