Click here to Skip to main content
15,891,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make call from angular to mvc controller action method. That action method has to redirect to another URL or return as view.

How do i hande this in angular $http call?

What I have tried:

var data = {
name: 'raj',
age: '35'
};
data = { 'model': data };
angularService.POST(URL, data)
.then(function (response) {

});
Posted
Updated 24-Dec-17 5:01am

1 solution

So, a couple of problems here. First, a web server (HTTP) is a request/response thing. You make a request from the client and the server ALWAYS returns a response, even if it's just an "success" message. There's no way around that.

Second, it sounds as though you're using the wrong return type in your MVC code. You don't have to return a view. You can return a JsonResult if you want. But, without seeing the code you're calling on the MVC side, it's impossible to tell you what you're doing wrong.

So, what do you want the method to return?
 
Share this answer
 
Comments
Raj kumar.C 24-Dec-17 22:27pm    
In Mvc action method has to redirect to another URL or redirect to another action method which will return diffrent view. so response should not back to angular success part.

if{isEnabled)
return View(viewModel);
else
return Redirect("http://mysite.com");
Dave Kreskowiak 25-Dec-17 11:48am    
OK, so the angular call has to be able to respond to the redirect. All the Redirect is doing is returning a RedirectResult, which the client side has to interpret and do whatever it wants with.

Just Google for "Angular redirect to url" for examples.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900