我有一个索引页面和一个子页面。在我的索引页面中,我试图渲染我的孩子。但如预期,并预期ASP.NET MVC中的角度路由合并
这里角路由不工作莫名其妙的东西不工作是我的索引页
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<body ng-app="AngularApp">
<div> My message {{message1}} </div>
<a href="FirstChild">First child</a>
<div></div>
<div ng-view></div>
</body>
@section scripts{
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/angular-resource.js"></script>
<script src="~/Modules/AngularApp.js"></script>
}
这里是我的angularApp.Js文件,我已经定义了路由
var myapp = angular.module('AngularApp', ['ngRoute']);
myapp.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/',
{
templateUrl: '/Index',
controller: 'IndexController'
})
.when('/FirstChild',
{
templateUrl: '/Angular/FirstChild',
controller: 'ChildController'
});
$locationProvider.html5Mode(true).hashPrefix('!')
});
myapp.controller('IndexController', function ($scope) {
alert('My Index');
$scope.message1 = "My Index";
});
myapp.controller('ChildController', function ($scope) {
alert('My Child Index');
$scope.FirstMessage = 'My First Message';
});
这是我的ASP.NET MVC操作,用于渲染局部视图。在ASP.NET MVC我的控制器名称为角
public ActionResult FirstChild()
{
return PartialView("Firstchild");
}
问题1:
当我运行与指数的应用为起始页面,这是URL,我米看到在浏览器中, http://localhost:59367/Angular/Index但在角侧的索引页对应的控制器不触发
问题2:
当我点击网络连接在我的索引页中的第一个子链接,它将我带到一个完整的页面,而不是在ng-view中渲染局部视图。
http://localhost:59367/Angular/FirstChild
我敢肯定有我在其中定义,但无法弄清楚角路由严重的问题:(请帮
问题摘要: 在进一步的分析,其被发现,一旦我点击“第一个孩子”,理想情况下URL应该像Angular/Index#/ FirstChild一样阅读,但是这里发生的是“ASP.NET MVC Action First Child被调用并且URL完全改变”
我认为这可能是由你的templateUrl期望一个html引起的,我想你应该写一些类似于:templateUrl:'views // main.html'。看看[http://stackoverflow.com/questions/24301092/angularjs-routeprovider](http://stackoverflow.com/questions/24301092/angularjs-routeprovider)就像你的路线的例子。 – AndreaM16
@ AndreaM16,我指的是这个网站http://www.wintellect.com/devcenter/dbaskin/angularjs-mvc-cookbook-simple-routing 也http://www.dotnetcurry.com/showarticle.aspx?ID = 1054其中partialview方法用于呈现.cshtml文件 – TechQuery