【发布时间】:2023-03-06 22:30:01
【问题描述】:
我无法弄清楚我的代码中发生了什么,所以这就是我想在论坛上发布我的问题的原因。
我正在尝试在我的 Asp.Net MVC 5.0 应用程序中使用 AngularJS 1.5 实现动态菜单,但是一旦我导航到其他菜单,页面就会冻结,所以你们能帮我解释一下为什么我的页面冻结了。
抱歉无法弄清楚到底是什么问题,所以请大家指点我...
用于填充菜单“_Layout.cshml”的代码
<header>
<nav ng-init="fillMenuController()" ng-controller="LayoutCtrl" class="navbar-inverse">
<div class="container-fluid">
<div class="navbar-header"></div>
<script type="text/ng-template" id="treeMenu">
<a class="dropdown-toggle" href="{{menu.URL}}" ng-attr-data-toggle="{{menu.URL == '#'?'dropdown':''}}">
{{menu.LinkText}}
<span ng-if="(MenuList | filter:{ParentCategoryID : menu.ID}).length > 0">
<span class="caret"></span>
<ul ng-hide="(MenuList | filter:{ParentCategoryID : menu.ID}).length == 0" class="dropdown-menu">
<li ng-repeat="x in MenuList | filter: {ParentCategoryID : menu.ID}">
<a href="{{x.URL}}">{{x.LinkText}}</a>
</li>
</ul>
</span>
</a>
</script>
<div class="navbar-header"><a href="#"><img class="img-responsive AngularJS-small" src="~/Images/ACE.jpg" style="height: 40px; padding-top: 10px;" /></a></div>
<ul class="nav navbar-nav">
<li class="dropdown" ng-repeat="menu in MenuList | filter: {ParentCategoryID : 0}" ng-include="'treeMenu'" />
<li id="btnLogOut"><a href="#">Log out</a></li>
</ul>
</div>
控制器代码
app.controller("LayoutCtrl", function ($scope, LayoutService, common) {
$scope.MenuList = [];
$scope.fillMenuController = function () {
var MenuMasterData = LayoutService.GetMenuMaster()
MenuMasterData.then(function (response) {
if (response.data.length == 0) { return; }
$scope.MenuList = response.data;
}, function (response) {
if (response.data != null)
{
common.ShowMessage(response.data);
}
});
}
});
app.service("LayoutService", function ($http) {
this.GetMenuMaster = function () {
var response = $http({
method: 'get',
url: "/Layout/GetMenuMaster",
params: {},
cache: true
})
return response;
};
});
用于填充动态菜单的数据库代码:
public JsonResult GetMenuMaster()
{
SAPDataContext objSAPDataContext = new SAPDataContext();
try
{
List<BE_Menu> lstMenu = new List<BE_Menu>
{
new BE_Menu { ID = 1, LinkText = "Activity", URL="/CRM/Activity/", ParentCategoryID = 0 },
new BE_Menu { ID = 2, LinkText = "Business Partners", URL="/CRM/BusinessPartner/", ParentCategoryID = 0 },
new BE_Menu { ID = 3, LinkText = "Sales", URL="#", ParentCategoryID = 0 },
new BE_Menu { ID = 4, LinkText = "Sales Opportunities", URL="/Opportunity/OpportunityMaster", ParentCategoryID = 3 },
new BE_Menu { ID = 5, LinkText = "Sales Quotation", URL="/CRM/SalesQuotation/", ParentCategoryID = 3 },
new BE_Menu { ID = 6, LinkText = "Sales Order", URL="/CRM/SalesOrder/", ParentCategoryID = 3 },
new BE_Menu { ID = 7, LinkText = "Delivery", URL="/CRM/Delivery/", ParentCategoryID = 0 },
new BE_Menu { ID = 8, LinkText = "Service Call", URL="/CRM/ServiceCall/", ParentCategoryID = 0 },
new BE_Menu { ID = 9, LinkText = "Customer Equipment Card", URL="/CRM/EquipmentCard/", ParentCategoryID = 0 }
};
return Json(lstMenu, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
finally
{
objSAPDataContext.Dispose();
}
}
现在我这边的一些输入我偶然发现了这个错误:http://localhost:36167/Scripts/AngularJS/angular.min.js 中第 133 行第 345 列的未处理异常
0x800a139e - JavaScript 运行时错误:[$rootScope:inprog] http://errors.angularjs.org/1.5.0/$rootScope/inprog?p0=%24diges
【问题讨论】:
标签: angularjs asp.net-mvc-4 razor