0

Can someone tell me if my settings are off. I created a registration page so that when the user hits submit, user gets redirected to the login page.

Here is my script:

<script type="text/javascript">
    app.controller('regController', function ($scope, $location, $http) {
        $scope.submitForm = function (isValid) {
            if (isValid) {
                $http({
                    method: 'POST',
                    url: '/RegModule/Account/Registration',
                    data: $scope.regData,
                    headers: { 'Content-Type': 'application/json' }
            }).success(function (data, status, headers, config) {
                $location.path('@Url.Action("Home/Home/Login")');

            }).error(function (data, status, headers, config) {

            })
        }
    }
})
</script>

Here is my app.config

var app = angular.module('MyApp', ["ngRoute"])
.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when("/Login", {
            templateUrl: "Home/Home/Login",
            controller: 'registrationController'
        });

    $locationProvider.html5Mode(true);
});

The problem I am running into is $location.path keeps appending the path I want to the current url instead of rewriting the whole path. For example, my current url is https://localhost/RegModule/Account/Registration. When the user hits submit, I tell it in the success method to redirect to https://localhost/Home/Home/Login. Instead my link ends up as: http://localhost/RegModule/Account/Registration#/Home/Home/Home/Home/Login

I've been googling this for the past 2 days and I can't figure out where my problem lies. Does anyone have any thoughts? Maybe i'm missing a setting i'm supposed to apply? I like to add in that that I am using ASP.NET MVC 5 behind the scenes.

1 Answer 1

0

Basically you are working with two routing engines. Asp.Net MVC has its own routing engine and AngularJS has its own. These two cannot work together at the same time . I will prefer to use one. I have issue in the past with this . This can be useful . I redefine the routes to follow Angular Routes not MVC routes.

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

4 Comments

If I get it to use angular routes, how do I get it to call the mvc actionresult methods in my mvc controllers?
routes.MapRoute( name: "Application", url: "{*url}", defaults: new { controller = "Home", action = "Index" }); Then there will be no MVC Action routing , then you will use ng-route only and setup routes accordingly.
I get this error when I apply routes.MapRoute to my route.config. HTTP Error 404.15 - Not Found The request filtering module is configured to deny a request where the query string is too long.
I fixed the error by adding an allow anonymous attribute to my index action results. The problem I have now is that every link I click redirects to that Index view in my home controller. I can't my Registration page to display.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.