0

I am having a porblem with the ng-view which doesn't want to load. If I press on a link I get the following Url: http://localhost:63024/Home/Index#/routeOne

Code for my controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
    public ActionResult One()
    {
        return View();
    }

    public ActionResult Two()
    {
        return View();
    }

    public ActionResult Three()
    {
        return View();
    }
}

So a very simple Controller.

And the following routing:

var configFunction = function ($routeProvider) {
$routeProvider.
    when('/routeOne', {
        templateUrl: 'Home/one'
    })
    .when('/routeTwo', {
        templateUrl: 'Home/two'
    })
    .when('/routeThree', {
        templateUrl: 'Home/three'
    });
}
configFunction.$inject = ['$routeProvider'];

myApp.config(configFunction);

And the following view:

<ul>
   <li><a href="#/routeOne">Route One</a></li>
   <li><a href="#/routeTwo">Route Two</a></li>
   <li><a href="#/routeThree">Route Three</a></li>
</ul>

<div ng-view></div>
4
  • 3
    You are mixing Angular routing (client side) with ASP.net routing (server side) - they aren't the same... typically you would use Angular routing to "navigate" to views without involving server routing (Angular will obtain a new view/template via Ajax/XHR) Commented Jan 23, 2016 at 2:50
  • So I should provide only one routing engine, either the Angular routing or the Asp.net routing? Commented Jan 23, 2016 at 10:39
  • Or can I combine Angular routing with Asp.net routing? Commented Jan 23, 2016 at 10:48
  • I don't want to say Angular is only for SPA (single page applications), because it is not, however, that is where it shines. I will also not say you can't mix server and client side when using Angular because you can (I do). It depends on what you are trying to accomplish - e.g. the famous "todo app" Angular tutorial could just be one part of your web site, where Angular does all the "todo application" processes/routing in a single "page" via AJAX/XHR (but the "page" itself in is an ASP.net view that a user navigated to from other parts of your web site via ASP.net routing). Hth.... Commented Jan 23, 2016 at 16:06

1 Answer 1

1

have you specified views for those controller actions in the mvc app, and ng-controller / ng-app on the angular side? (posting this as answer as i can't post a comment)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.