c# - AngularJs $http.post 不渲染新 View

标签 c# javascript asp.net-mvc angularjs

我有这个 AngularJs http.post-function。在我看来,我有一个 Id:s 列表。当我点击任何一个 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?帖子ID 并且 actionResult 开始渲染,如果我调试它,我可以看到它将进入其 View (SingleBlogPost.cshtml)

但是如果我在浏览器中观看会发生什么,一切都保持不变。我仍然保持着从一开始的观点。为什么我的 SingleBlogPost Actionresult-view 没有在浏览器中呈现?为什么我仍然在同一页面上,即使 SingleBlogPost 方法被命中并在我调试时查看它的 View ?

//谢谢

最佳答案

操作完成后尝试添加 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;


});

关于c# - AngularJs $http.post 不渲染新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25475577/

相关文章:

javascript - WebGL 动画下的 HTML 内容不可点击

javascript - 从spring Controller 重定向到jsp页面

asp.net-mvc - 从网站到外部 Web api 的简单 POST 失败

asp.net-mvc - 部署 Web 应用程序时出错 "Could not open Source file: Could not find a part of the path"

c# - 如何控制和调整Windows 7 中的音量?

c# - 在 Windows Azure 中部署 WCF 应用程序

c# - 如何指定 AddIn 进程名称?

c# - 在 C# 中拆分字符串

javascript - Jquery 未捕获错误

asp.net-mvc - 如何在编辑页面 MVC 中设置下拉列表选定值