0

I am trying to navigating from login page to Home page but it is not navigating to login page even though it is hitting HomeController, here i used angularjs http.get service for navigating.

I have verified RouteConfig settings, but am unable to find the problem where it is.

Below is route config

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

angular code

(function () {
    var app = angular.module("AngularApp", []);
    app.service("loginservice", function ($http) {

        this.Checkuser = function (UserName, password) {
            return $http({
                method: "Post",
                url: "Login/LoginUserAuth/",
                data: { UserName: UserName, password: password }
            });
        }
        this.NavigateToHome = function (UserName) {
            return $http({
                method: "get",
                url: "Home/Index"
            });
        }
    });

    app.controller("LoginController", function ($scope, $http, loginservice) {
        $scope.Checkuser = function () {
            var checkresult = loginservice.Checkuser($scope.username, $scope.password);
            checkresult.success(function (dataFromServer, status, headers, config) {
                //alert(dataFromServer);
                if (dataFromServer == '"Login Success"') {
                    var NavigateToHome = loginservice.NavigateToHome($scope.username);
                }
                else {
                    alert('Wrong UserName or Password');
                }
            });
            checkresult.error(function () {
                alert('Error in Login');
            });
        }
    });
}
())

Home controller

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
}
13
  • 1
    $http won't redirect you to any page, it'll just return a promise. use window.location.href = 'yoururl' inside javascript Commented Jan 17, 2015 at 19:05
  • if you are using $routeProvider then use $location.path('url') Commented Jan 17, 2015 at 19:06
  • but it is hitting the controller method, but it is not showing the view Commented Jan 17, 2015 at 19:08
  • its because of you are making ajax to that controller action,,, Commented Jan 17, 2015 at 19:10
  • instead of $http call put this.NavigateToHome = function (UserName) { window.location = '/home'; } Commented Jan 17, 2015 at 19:11

0

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.