I am using ASP.net MVC and AngularJS. In my current page I select some items and on button click the angular function is called
var itemIds = [];
//... somehow I get my items from the grids
var url = 'http://localhost/myController/CompareItems';
$http.post(url, groupIds)
.then(function (response) {
// var data = response.data;
//what to do here?
}
).finally(function () {
vm.loading = false;
});
}
The c# MVC controller is like below: (myController.cs)
public async Task<IActionResult> CompareItems([FromBody] int[] itemIds)
{
var model = new CompareModel
{
property1= ..,
property2= ..,
......
......
};
return View("CompareItems",model);
}
On $http.post call, the debugger comes to the above controller, prepare the model and should return the View. There is no error but the page is not redirecting. What is wrong here?
N.B: I have searched many other posts before asking this question. I found lots of people are suggesting RedirectToAction. I tried this and that doesnot work. My question is, why should Redirect to another action. I am already in my expected action method with my required param values.
The thing is very simple, just collect the selected items from javascript and pass it to mvc controller-action. It is return a different view.