I'm a bit confused about using the routing of Angular within an Asp.Net MVC app.
To understand my question I will shown the currently code of my app:
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();
}
}
}
My Angular module:
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: '/'
});
}
The output URL is shown as follows: localhost/Home/Index#/test1
Question:
Do I need to define Actions in HomeController and why? I thought I need just the ActionResult Index because I use PartialView()... And how can I achieve the following URL: localhost/test1
when I click on the Menu Test1?