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?
NB: 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.
There appear to be something you missing.
You might want to replace
return View("Login")
with
return RedirectToAction("Login");
I am just giving an instance , you might want to replace it with what you have.
Calling View from another folder
return View("MyViewFolder/MyViewName.cshtml");
Or with model as object
return View("MyViewFolder/MyViewName.cshtml", model);
Please also check you have set method return type as async
which may prevent you if some ongoing execute are there with await.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.