Asp.Net MVC 앱에서 Angular 라우팅을 사용하는 것에 대해 다소 혼란스러워합니다.ASP.NET MVC에서 각도 라우팅을 정의하는 방법
Index.cshtml :
<head>
...
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-collapse collapse glyphicons pull-right">
<ul class="nav navbar-nav">
<li ng-class="{active:isActive == '/test1'}">
<a href="#/test1">Test1</a>
</li>
<li ng-class="{active:isActive == '/test2'}">
<a href="#/test2">Test2</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
<div ng-view></div>
</div>
@Scripts.Render("~/bundles/angular")
@Scripts.Render("~/bundles/app")
</body>
HomeController (ASP.NET) :
namespace Tests.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return PartialView();
}
public ActionResult Test1()
{
return PartialView();
}
public ActionResult Test2()
{
return PartialView();
}
}
}
내가 내 응용 프로그램의 현재 코드를 표시합니다 내 질문을 이해하려면 내다음과 같이
angular
.module('Tests', [
'ngRoute'
])
.config(config)
.run(['$rootScope', '$route', '$location', function($rootScope, $route, $location) {
$rootScope.$on('$routeChangeSuccess', function(event, currRoute, prevRoute) {
$rootScope.title = $route.current.title;
});
var path = function() {
return $location.path();
};
$rootScope.$watch(path, function(newPath, oldPath) {
$rootScope.isActive = newPath;
});
}]);
config.$inject = ['$routeProvider'];
function config($routeProvider) {
$routeProvider
.when('/test1', {
templateUrl: '/Home/Test1',
isActive: 'test1'
})
.when('/test2', {
templateUrl: '/Home/Test2',
isActive: 'test2'
})
.otherwise({
redirectTo: '/'
});
}
출력 URL이 표시됩니다 : localhost/Home/Index#/test1
질문 :
내가 왜 HomeController와의 작업을 정의해야합니까? PartialView()를 사용하기 때문에 ActionResult Index가 필요하다고 생각했습니다. 다음 URL을 어떻게 얻을 수 있습니까? localhost/test1
Menu Test1을 클릭하면 어떻게됩니까?
내 대답을 참조하십시오. 이해가되는지 알려주세요. 당신이 맞지 않는다면, 나는 아마도 내가 공유 할 수있는 작은 개인 git repo가 있지만 먼저 익명화해야 할 것입니다. –
이것을 읽어보십시오. http://stackoverflow.com/questions/20801780/angular-ng-include-cshtml-page 각도 라우팅 + MVC 라우팅에 대한 – Pravin
참조 예. https://angularjsaz.blogspot.in/2015/10/angularjs-routing-aspnet-mvc-example.html – Pravin