AngularJs + MVC 4 and routing using AngularJs after dashboard

505 views
Skip to first unread message

deeksha sharma

unread,
Jan 24, 2014, 11:38:17 AM1/24/14
to ang...@googlegroups.com
Hi,



I am new to AngularJs .and working on project.

We have used Mvc4 with WebApi  and  We made Login using simple mvc4 structure but after login .we call http://localhost:23434/Home/Index.

and on Index page we want to implement SPA using AngularJs  but I am facing problem with routing because it is not taking the Html page via controller.
where can i add Html page for making the routing  properly.

Mauro Servienti

unread,
Jan 24, 2014, 1:45:16 PM1/24/14
to ang...@googlegroups.com
Would mind diving a bit more into the issue? Because I’m using the same backend stack with no problems at all.
I’m putting my AngularJS markup into the Views/Index.cshtml razor view. What do you mean by "it is not taking the Html page via controller”?

.m

deeksha sharma

unread,
Jan 24, 2014, 11:34:49 PM1/24/14
to ang...@googlegroups.com
Yes.Mauro,


For Login we used MVC$ structure and after that we call the MVC view using Home Controller and Index view. So, I have a question We want to make Index.cshtml  as SPA . and for this I have added no. of html pages in Home folder of View . But the Url searched by angular 
localhost:23454/Home/View/Index.html and ,when I see it using firebug. error what I found i.e. http 404 not found.



we have used two controller in angularjs to load these two Html pages. 
Inew.html and List.html 


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/43Rh4LjFTJg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Mauro Servienti

unread,
Jan 25, 2014, 2:18:47 AM1/25/14
to ang...@googlegroups.com
For Login we used MVC$ structure and after that we call the MVC view using Home Controller and Index view. So, I have a question We want to make Index.cshtml  as SPA . and for this I have added no. of html pages in Home folder of View . But the Url searched by angular 
localhost:23454/Home/View/Index.html and ,when I see it using firebug. error what I found i.e. http 404 not found.


The best practice is to put the SPA in a “App” folder at the root level, something like:
localhost:23454/App/Presentation/Index.html

I suppose (just suppose) that the 404 error is raised by the MVC routing engine that can find a HomeController but cannot find a View action on the controller.

.m

Dave Solenovex

unread,
Jan 25, 2014, 2:27:52 AM1/25/14
to ang...@googlegroups.com
I'm using mvc 5 and web api. It works for me...
the url in the address bar is like this : http://localhost:28878/#/Register this is from the Default mvc home controller.
for other mvc controller's page, urls are like this: http://localhost:28878/Backend/Admin#/Role

there is always a '#' after asp.net mvc's action path.

here is the code in the menu:
<ul class="nav navbar-nav">
                    <li><a href="#Resource">资源列表</a></li>
                    <li><a href="/Home/Feature/#/overview">碟包推荐</a></li>
                    <li class="dropdown" ng-show="user">
                        <a href="#" target="_self" class="dropdown-toggle" data-toggle="dropdown">系统管理 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="#Role">角色管理</a></li>
                        </ul>
                    </li>
                </ul>

here is the code in app.js:
var app = angular.module('app', ['ngRoute', 'ngSanitize', 'controllers', 'services'])
    .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
        $routeProvider
            .when('/', {
                templateUrl: '/Features/Home/home.html',
                controller: 'homeCtrl',
            })
            .when('/Register', {
                templateUrl: '/Features/Account/register.html',
                controller: 'registerCtrl',
            })
            .when('/Login/:returnUrl?', {
                templateUrl: '/Features/Account/login.html',
                controller: 'loginCtrl',
            })
            .when('/ChangePassword', {
                templateUrl: '/Features/Account/changePassword.html',
                controller: 'changePasswordCtrl',
            })
            .when('/Role', {
                templateUrl: '/Features/Administration/role.html',
                controller: 'roleCtrl',
            })
            .otherwise({
                redirectTo: '/',
            });
    }]);

deeksha sharma

unread,
Jan 26, 2014, 1:48:34 PM1/26/14
to ang...@googlegroups.com
thanks Mauro, now  my problem is resolved . its working for me.



--
Reply all
Reply to author
Forward
0 new messages