在asp.net mvc中执行Homecontroller后,View不显示

时间:2015-01-17 19:02:23

标签: angularjs asp.net-mvc

我正在尝试从登录页面导航到主页但是它没有导航到登录页面,即使它正在点击HomeController,这里我使用angularjs http.get服务进行导航。

我已经验证了RouteConfig设置,但无法找到问题所在。

以下是路线配置

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

角度代码

(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');
            });
        }
    });
}
())

家庭控制器

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
}

0 个答案:

没有答案