我有两个布局,第一个用于访问者,第二个用于管理
溃败:
app.config(['$routeProvider',
function ( $routeProvider) {
$routeProvider
.when('/', { templateUrl: 'Home/Main', })
.when('/Manage', { templateUrl: 'Manage/Index', caseInsensitiveMatch: true })
.when('/Manage/Item/:itemId?', { templateUrl: '/Item/Index/',caseInsensitiveMatch: true});
}
]);
home/index 中的第一个 ng-view 和 manage/index 中的第二个 ng-view 但是/Item 未在管理 ng-view 中加载
最佳答案
MVC 中的 IMO 区域非常糟糕。我讨厌复制大部分 MVC 应用程序只是为了呈现不同布局的想法。
在我的情况下,我有一个用于用户未通过身份验证的布局,以及另一个用于用户经过身份验证的布局。就我而言,我在 MVC 应用程序之上有一个 AngularJS SPA。因为它是一个 SPA,所以我有一个带有 <div ng-view></div>
的 View 元素。我实现的解决方案利用了 _ViewStart.chtml 文件:
@{
if (User.Identity.IsAuthenticated)
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
else
{
Layout = "~/Views/Shared/_UnauthorizedLayout.cshtml";
}
}
我正在对公开的 IPrincipal 对象使用条件,但您可以在其中放置您想要的任何条件逻辑。
关于javascript - 在 asp.net mvc 中使用 angularjs 进行多重布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25758327/