Skip to content Skip to sidebar Skip to footer

Asp.net 5 Routing Navigation With Angularjs

I'm using ASP.NET 5 with AngularJS. I've 2 actions with views in MVC (Home and Web). I've 4 client routing with Angular. All of these 4 client routing happens in first view (Home).

Solution 1:

try to use the mvc controllers from angular in the following way:

In your angular file use the template URL for referencing the mvc controller:

app.config(["$stateProvider", "$urlRouterProvider", "$locationProvider",      function ($stateProvider, $urlRouterProvider, $locationProvider) {

$urlRouterProvider.otherwise('/');

$stateProvider
.state('home', {
    templateUrl: 'home/Home'
})
.state('about', {
    templateUrl: 'home/About'
})
.state('contact', {
    templateUrl: 'home/Contact'
})
.state('tutorial', {
    templateUrl: 'home/Tutorial'
})

$locationProvider.html5Mode(true);

}]);

And return the views as partial views in the mvc controller adding the functionality that you want

publicclassHomeController : Controller
{
    [Route("{*url}")]
    public IActionResult Home()
    {
        return View();
    }

    [Route("Home/About")]
    public IActionResult About()
    {
        return View();
    }

    [Route("Home/Contact")]
    public IActionResult Contact()
    {
        return View();
    }

    [Route("Home/Tutorial")]
    public IActionResult Tutorial()
    {
        return View();
    }
}

Hope it helps

Post a Comment for "Asp.net 5 Routing Navigation With Angularjs"