Click here to Skip to main content
15,125,547 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do I redirect to Home page after I login.. Below I added my Login controller and View and related JavaScript. Please help me soon.
This is my Controller:

        public JsonResult Login(User user)
            Response Res = new Response();
            string data = "";
                List<user> userlist = new List<user>();
                userlist = us.getByname(user.UserName);
                User U = new User();
                if (userlist.Count > 0)
                    U = userlist.SingleOrDefault(a => a.Password == user.Password);
                    if (U != null)
                        data = "Login Success";
                        data = "Login faliur";

                data = "Login faliur";
            return Json(data,JsonRequestBehavior.AllowGet);

and, this is my View along with the necessary JavaScript:

div class="container"&gt;
        <div ng-controller="lnCtrl">
            <form class="form">
                <input type="text" ng-model="user.UserName" placeholder="Username">
                <input type="password" ng-model="user.Password" placeholder="Password">
                <button type="submit" ng-click="Login(user)" id="login-button">Login</button>

var AlApp = angular.module("AlApp", []);
    AlApp.controller("lnCtrl", function ($scope, $http, $log) {
        var Us = $scope.user;
        $scope.Message = "Login";
        $scope.Login = function (Us) {
            //var Us = $scope.Us;
                method: "Post",
                url: "/login/Login",
                data: JSON.stringify(Us),

                //data: Us

            }).success(function (data) {
                $scope.Message = data;

            }).error(function (err) {

                $scope.Message = err.Message;
Updated 1-Dec-15 3:35am
F-ES Sitecore 1-Dec-15 9:26am
Just use a normal form.

If you are using ajax call, you have to return the url in your "data" for example like data.url and use:

// similar behavior as an HTTP redirect

// similar behavior as clicking on a link
window.location.href = data.url;

Since you are working with Ajax form submission, you can not redirect to another view from controller action. So you need to do this on client side after ajax get success.
So put window.location=''; into the java script code as:

}).success(function (data) {
               $scope.Message = data;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900