Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I went through the process of starting a new ASP.NET MVC no-user authentication process, and have already began integrating AngularJS with C# code.

My _ViewStart.cshtml uses _Layout.cshtml to @RenderBody() for each of my Views found under Views->Home. I have my two views, Index.cshtml and SignUp.cshtml.

In the Index partial view, I have a form that has an action controlled by this AngularJS function:

.controller('LoginController', function ($scope, $location, LoginService) {
    $scope.LoginData = {
        CID: '',
        Email: ''
    };

    $scope.Login = function ($window) {
        $scope.Submitted = true;
        if ($scope.IsFormValid) {
            LoginService.GetUser($scope.LoginData).then(function (d) {
                if (d.data.CID != null) {
                    loginCID = d.data.CID;
                    loginEmail = d.data.Email;
                    $scope.Message = "Successfully logged in. Welcome " + d.data.CID;
                    $location.path("/Home/SignUp");
                }
                else {
                    alert("Invalid Creds");
                }
            });
        }
    };
})

I've omitted in included any extra code that wasn't entirely necessary for this question so extra variables/factories/services have been excluded. The code all works except for this line:

$location.path("/Home/SignUp");

Once the form is filled out, $scope.Message changes to what's in the if statement, and the URL changed from http://localhost:61660/ to http://localhost:61660/Home/SignUp But the partial view for Index still shows. Meaning, I'm still seeing Index.cshtml being rendered in the body and not SignUp.cshtml. How can I change this to actually redirect?

share|improve this question
up vote 0 down vote accepted

Try this approach instead of $location.path("/Home/SignUp"):

window.location.pathname = 'Home/SignUp';

It is caused, because angular intercepts $location's redirections and process them by means of own's routing infrastructure, preventing your's expected behavior.

share|improve this answer
    
I just ran into a problem. If I place a console.log('test') inside the SignUpController.js nothing is output on the console when it navigates over. – VolcovMeter Jul 18 at 15:48
    
Try to go to this page directly from browser and check will log's message appear at console or not. – Slava Utesinov Jul 19 at 5:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.