2

I am trying to anularize a legacy asp.net mvc4 application. After the web api http.put is executed inside the angular js controller, I would like the page to be directed to another asp.net mvc4 action/controller. How is it possible?

$scope.saveEditProfile = function () {
    $http.put("/api/ProfileWeb", $scope.profile)
        .then(function(response) {
            $scope.profile = response.data;
        });

// need some sort of reroute instruction here to route to asp.net mvc Action = Inedex and Controller =Profile.

};
3
  • You would not be able to use the response.data if you process to a redirect. If by redirect you mean "another view", you can use the $location service. In any other case, you should wait for the promise resolution to be sure the query has been done, and handle errors if needed. Do your redirection only after that. Commented Oct 24, 2014 at 14:39
  • At this point, I am interesetd in response.data. If the put operation is successful, I would like to execute redirect to another view Commented Oct 24, 2014 at 14:45
  • so how do I redirect? Commented Oct 24, 2014 at 14:59

1 Answer 1

3

You can use

  window.location ="/Profile/Index";

ie:

    $scope.saveEditProfile = function () {
            $http.put("/api/ProfileWeb", $scope.profile)
                .then(function(response) {
                    $scope.profile = response.data;    
                  window.location ="/Profile/Index";        
       }); 

  };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.