2014-09-28 3 views
0

// AngularJS 및 제어 방법리디렉션 MVC

$scope.onLogOutClick = function() // called when i clicked on logout button 
     { 

         //i want here to redirect to login.cshtml file. 
        $http({ method: 'GET', url: "/Home/Login"}); 
         // this line of code is not working. 

     } 

제어기 // 메소드 리턴 logic.cshtml보기 AngularJS와 컨트롤러 페이지 cshtml한다.

[HttpGet] 
    public ActionResult Login(string theme, string feature) 
    { 
     return View("login"); // i want to render this view in angularJs 
    } 

logout 버튼을 클릭하면 onLogOutClick() 메서드가 호출됩니다. 로그 아웃 버튼을 클릭했을 때 login.cshtml 페이지로 다시 리디렉션하고 싶습니다.

+0

당신이 MVC 사용 또는 AngularJS와 로그인하는 사용자를 리디렉션하는 2) 로그 아웃 페이지

.when('/Logout', { templateUrl: '/Login/LogoutUser', controller: 'LogoutController' }) 

3) 컨트롤러를 다음과 같은 추가에 대한 라우팅을 추가 ?? – harishr

+0

나는 angularjs에서 mvc (.cshtml) 파일로 라우팅을 원한다. 실제로 우리의 응용 프로그램은 첫 번째 페이지를 mvc 나중에 하위 시퀀스 페이지를 통해로드합니다 angularJs에 만들어집니다. 로그 아웃을 클릭하면 첫 번째 페이지 (MVC (.cshtml 페이지)에 있음)로 리디렉션하고 싶습니다. – chirag

+3

mvc에서 cshtml이 아닌 controller/action으로 연결하면 ... – harishr

답변

0

AndularJs를 사용하여 단일 페이지 응용 프로그램 (SPA)을 개발할 수 있습니다. SPA에는 오직 하나의 CSHTML 파일 (Main Page)이 있으며 ng-view 및 $ roughtConfig 지시문을 사용하여 뷰를 변경합니다 (html 렌더링). 따라서 cshtml 페이지를 전환 할 수있는 경우는 없습니다.

+0

이것은 올바르지 않습니다. 작업 당 독립 단일 페이지 응용 프로그램 모음으로 MVC를 개발하고 인증을 오프로드하고 MVC로 템플릿 렌더링까지도 가능합니다. 공평하게하기 위해 시나리오와 요구 사항에 따라 아키텍처를 다양하게 조합 할 수 있습니다. 이 대답은 잘못 생각한 질문에 답하는 싼 기회처럼 보입니다. –

0

1) 빈 Logout.cshtml 페이지를 추가하십시오. 라우팅 페이지

angular.module('Application').controller("LogoutController", ['$scope', '$http', '$timeout', function LogoutController($scope, $http, $timeout) { 
    var requestLogout = $http({ 
     method: "POST", 
     url: "/api/LoginUser/LogoutUser" 
    }); 
    requestLogout.success((function myNewfunction() { 
     window.location.href = "/Login?session=false"; 
    })); 
}]);