Calling Asp.Net MVC 5 View from AngularJS Controller -


i trying redirect home page after successful login. currently, using asp.net mvc 5, angularjs, entityframework 6, bootstrap , repository pattern. below code logincontroller:

public jsonresult userlogin(studentmanagementuser data)     {         var user = repository.userlogin(data);         return new jsonresult { data = user, jsonrequestbehavior = jsonrequestbehavior.allowget };     } 

code angularjs controller:

app.controller("mvcloginctrl", function ($scope, loginajservice) { $scope.isloggedin = false; $scope.message = ''; $scope.submitted = false; $scope.isformvalid = false;  $scope.logindata = {     username: '',     userpassword: '' };  //check form valid or not // here f1 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!');             }         });     } };}); 

and code angularjs service:

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

i want redirect student/index.cshtml after successful login. how can achieve this?

have tried:

return json  (    new {            data = user,            jsonrequestbehavior = jsonrequestbehavior.allowget,            redirecturl = @url.action("userlogin", "logincontroller")        } ); 

and in angular in $http.post wait success callback:

success: function(data) {     window.location.href = data.redirecturl; } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -