美元AngularJs http.post不渲染新视图
本文关键字:新视图 post AngularJs http 美元 | 更新日期: 2023-09-27 18:19:20
我有这个AngularJs http.post-function。在我看来,我有一个Id列表。当我点击这些Id:s时这个函数就会被点击
$scope.GoToSinglePost= function (id) {
console.log(id);
if (confirm("Go to blogPost with " + id + " ?")) {
$http.post("/Home/SingleBlogPost", { postId: id });
}
};
这里一切都很好,帖子让我到我的mvc c# actionresult巫婆是下面这个:
public ActionResult SingleBlogPost(int? postId)
{
var singlePost = _repo.GetSinglePost(postId);
var viewModel = new SingleBlogPostViewModel()
{
Post = singlePost
};
return View(viewModel);
}
在这个ActionResult中,我从angularPost发送的postId得到了参数int? postId
然后actionResult开始渲染如果我调试它,我可以看到它会进入它的视图(singleblogpost。cshtml)
但是如果我在浏览器中观看,一切都保持不变。我仍然站在我一开始的观点上。为什么我的SingleBlogPost actionresultview在浏览器中渲染不了?为什么我仍然在同一页上,即使singleblogpost方法被击中,并通过它的视图,当我调试?
//谢谢
尝试在操作完成后添加success
或then
以执行进一步的操作,如:
$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;
});