Reputation: 1373
I'm having this AngularJs http.post-function. In my view I have a list of Id:s. And when I click on any of these Id:s this function gets hit.
$scope.GoToSinglePost= function (id) {
console.log(id);
if (confirm("Go to blogPost with " + id + " ?")) {
$http.post("/Home/SingleBlogPost", { postId: id });
}
};
Everything works fine here and the post gets me to my mvc c# actionresult witch is this one below:
public ActionResult SingleBlogPost(int? postId)
{
var singlePost = _repo.GetSinglePost(postId);
var viewModel = new SingleBlogPostViewModel()
{
Post = singlePost
};
return View(viewModel);
}
In this ActionResult the postId i've sent from my angularPost gets in to the parameter int? postId
And the actionResult starts to render and it's if I debug it, I can see that it will go in to its view (SingleBlogPost.cshtml)
But what happens if I watch it in my browser, everything stays the same. I'm still in the same view where I was from the beginning. Why doesn't my SingleBlogPost Actionresult-view renders in the browser? Why I'm I still on the same page even though the SingleBlogPost-method gets hit and goes thuogh it's view when I debug?
//Thanks
Upvotes: 2
Views: 735
Reputation: 2449
try adding a success
or then
once the operation is complete to perform further actions there, something like:
$http.post("/Home/SingleBlogPost", { postId: id }).success(function(data) {
//data is your response from server to the request;
//do something with data here, like changing to correct view;
});
Upvotes: 2