AngularJs $ http.post不呈现新的View

时间:2014-08-24 19:37:41

标签: c# javascript asp.net-mvc angularjs

我有这个AngularJs http.post-function。在我看来,我有一个Id:s列表。当我点击这些Id中的任何一个时,这个功能就会被击中。

$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 Actionresult-view在浏览器中呈现?为什么我仍然在同一页面上,即使SingleBlogPost方法受到攻击并在调试时查看它的视图?

//由于

1 个答案:

答案 0 :(得分:2)

尝试在操作完成后添加successthen以执行其他操作,例如:

$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;


});
相关问题