2016-05-08 5 views
0

投稿要求をLoginRedirectToActionに送信するときに、なぜURLが/Home/Secondに変更されないのですか?ASP.NET mvc angularjs投稿がリダイレクトされない

AngularJS:

$scope.answer = function(answer) { 
    $mdDialog.hide(answer); 
    $http({ 
     method: 'POST', 
     url: 'Home/Login', 
     data: JSON.stringify({ email: $scope.user.email, password: $scope.user.password }) 
    }); 
}; 

にHomeController:

public class HomeController : Controller 
{ 
    // 
    // GET: /Home/ 

    public ActionResult Index() 
    { 
     return View(); 
    } 
    [HttpGet] 
    public ActionResult Second() 
    { 
     return View(); 
    } 

    [HttpPost] 
    public ActionResult Login(string email,string password) 
    { 
     return RedirectToAction("Second"); 
    } 
} 

答えて

0

代わりのあなたは下like Angular JSコードからそれをリダイレクトすることができ、コントローラからそれをリダイレクトします。

あなたのJSコードは

$scope.answer = function(answer) { 
      $mdDialog.hide(answer); 
      var response = $http({ 
       method: 'POST', 
       url: 'Home/Login', 
       data: JSON.stringify({ email: $scope.user.email, password: $scope.user.password }) 
      }); 

     if(response == "Success") 
     { 
      $window.location.href = "/Home/Second"; 
     } 

    }); 

され、あなたのコントローラであなたは、このようにあなたの方法を記述する必要があります。

public string Login(string email,string password) 
{ 
     return "Success"; 
} 
関連する問題