Quantcast
Viewing all articles
Browse latest Browse all 7

Answer by vishwajeet kumar for AngularJs routing with Asp.Net Mvc

Lets understand the routing in angular first. lets say your url says

www.example.com/Home/Index -- this points to your MVC HomeController and Index ActionMethod. Now what mvc does, it returns you the first View only.

say you have an anchor Load the New View. Clicking this will result in a new Url www.example.com/Home/Index#/angular-route. This url will still hit the same MVC HomeController and ActionMethod.But you have an additional route in angular

`var app = angular.module('ProjectTrackingModule', ['ngRoute', 'ui.bootstrap']); app.config(function ($routeProvider) {    $routeProvider        .when("/angular-route", {        templateUrl: "/Html/GetHtml?type=angular-route",        controller:"AngularController"    })       .otherwise({redirectTo:"/Home"})});`

Here in the code section templateUrl: "/Html/GetHtml?type=angular-route",

Html is MVC Controller and GetHtml is ActionMethod. This ActionMethod returns you the new view that you want according to the angular route, that's why we are sending a parameter type too to help us decide.

controller:"AngularController" says that angular will call its controller after the page is returned from you mvc controller. It's Angular's Controller and it has nothing to do with your MVC controller.

you declare angular controller like this:

 app.controller('AngularController',function($scope){        alert("my js controller is called");    });

Hope this helps you to find a solution.


Viewing all articles
Browse latest Browse all 7

Trending Articles