【发布时间】:2015-05-18 10:10:53
【问题描述】:
在我的情况下,我需要使用 @Html.ActionLink 来使用 AngularJS 路由到不同的视图。在 asp.net 中的每个 view1/index.cshtml 中都有 <div ng-view></div> 将加载其 html 模板.
以下链接图片是我的项目结构:
click
我的问题是:它只是第一次路由成功。我认为它会导致错误的位置 url。
视图/共享/_Layout.cshtml:
<ul>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Device Management", "Index", "DeviceManagement")</li>
</ul>
视图/主页/index.cshtml:
@{
ViewBag.Title = "Home Page";
ViewBag.InitModule = "homeIndex";
}
@section Scripts {
<script src="~/app/home/homeIndex.js"></script>
}
<div ng-view><div>
app/home/homeIndex.js
var homeIndex = angular.module('homeIndex', ["ngRoute"]);
homeIndex.config(["$routeProvider", function($routeProvider){
$routeProvider
.when("/home",{
templateUrl:"app/home/homeIndex.html",
controller:"homeCtrl"
})
.otherwise({
redirectTo:"/home"
});
}]);
app/home/homeIndex.html
<a href="#/home2">HOME2</a>
app/deviceManagement/deviceManageIndex.js
var deviceManageIndex = angular.module('deviceManageIndex', ["ngRoute"]);
deviceManageIndex.config(["$routeProvider", function($routeProvider) {
$routeProvider
.when("/device", {
templateUrl: "app/deviceManagement/deviceManagementIndex.html",
controller: "deviceManageCtrl"
})
.otherwise({
redirectTo:"/device"
});
}]);
网站有侧边栏,主页和设备管理在侧边栏中的按钮。
当我点击Home时,它会重定向正确的位置,它可以成功加载homeIndex.html:
位置是:
http://localhost:13060/#/home
但是当我第二次单击 Home 按钮时,它无法再加载 homeIndex.html。
位置将更改为:
http://localhost:13060/#
同样的问题发生在另一个按钮设备管理
当我点击设备管理时,它会重定向正确的位置,它可以成功加载deviceManagementIndex.html:
位置是:
http://localhost:13060/DeviceManagement#/device
但是当我第二次点击设备管理按钮时,它不能再加载deviceManagementIndex.html了。
位置将更改为:
http://localhost:13060/DeviceManagement#
我觉得位置很奇怪,第一次应该是:
http://localhost:13060/DeviceManagement/#/device
我猜这是没有正确加载 html 模板的主要原因...
但是为什么位置url不能正确显示,请帮我解决头痛的问题....
【问题讨论】:
-
谁能救我,,,求助:'0
-
路由仅在客户端,不会重定向到原始 URL。也许我看错了,但我认为您需要将其作为回调处理,然后使用 $window.location 手动设置。
标签: asp.net-mvc angularjs routes html.actionlink ng-view