【发布时间】:2016-07-28 10:04:12
【问题描述】:
我尝试在成功登录后重定向到主页。目前,我正在使用 ASP.NET MVC 5、AngularJS、EntityFramework 6、引导程序和存储库模式。下面是我的 LoginController 的代码:
public JsonResult UserLogin(STUDENTMANAGEMENTUSER data)
{
var user = repository.UserLogin(data);
return new JsonResult { Data = user, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
AngularJS 控制器的代码:
app.controller("mvcLoginCtrl", function ($scope, loginAJService) {
$scope.IsLoggedIn = false;
$scope.Message = '';
$scope.Submitted = false;
$scope.IsFormValid = false;
$scope.LoginData = {
USERNAME: '',
USERPASSWORD: ''
};
//Check is Form Valid or Not // Here f1 is our form Name
$scope.$watch('f1.$valid', function (newVal) {
$scope.IsFormValid = newVal;
});
$scope.Login = function () {
$scope.Submitted = true;
if ($scope.IsFormValid) {
loginAJService.GetUser($scope.LoginData).then(function (d) {
if (d.data.USERNAME != null) {
$scope.IsLoggedIn = true;
$scope.Message = "Successfully login done. Welcome " + d.data.FULLNAME;
}
else {
alert('Invalid Credential!');
}
});
}
};});
和我的 AngularJS 服务的代码:
app.service("loginAJService", function ($http) {
this.GetUser = function (d) {
var response = $http({
method: "post",
url: "Login/UserLogin",
data: JSON.stringify(d),
dataType: "json"
});
return response;
};});
我想在成功登录后重定向到 Student/Index.cshtml。我怎样才能做到这一点?
【问题讨论】:
标签: angularjs asp.net-mvc-5 entity-framework-6