我有这个 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 ?
//谢谢
最佳答案
操作完成后尝试添加 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;
});
关于c# - AngularJs $http.post 不渲染新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25475577/