【问题标题】:MVC RedirectToAction is redirecting to different method [duplicate]MVC RedirectToAction 正在重定向到不同的方法[重复]
【发布时间】:2017-08-05 21:03:31
【问题描述】:

在我的控制器中,我有三种方法:

    public ActionResult DisplayPostsComments()
    {
        var viewModel = new DisplayPostsCommentsWiewModel();
        return View(viewModel);
    }


    [HttpPost]
    public ActionResult DisplayPostsComments(DateTime start, DateTime end)
    {
        List<PostModel> postList = new List<PostModel>();
        var posts = postDAL.GetPost(start, end);
        var comments = commentDAL.GetComments(posts);
        var viewModel = new DisplayPostsCommentsWiewModel(posts, comments);
        viewModel.start = start;
        viewModel.end = end;
        return View(viewModel);
    }


    public ActionResult DeleteComment(int commentId, DateTime start, DateTime end)
    {
        // commentDAL.DeleteComment(commentId);
        return RedirectToAction("DisplayPostsComments", new { start = start, end = end });
    }
}

我期待

return RedirectToAction("DisplayPostsComments", new { start = start, end = end });

用参数调用第二种方法。但我所取得的是对第一种方法的调用。我做错了什么?

【问题讨论】:

  • 为什么不自己调用 DisplayPostsComments 方法呢?
  • 请注意,model-view-controller 标签是针对有关模式的问题。 ASP.NET-MVC 实现有一个特定的标记。

标签: c# asp.net-mvc


【解决方案1】:

Redirect 向客户端返回“302 Redirect”响应,强制它向提供的位置发出 GET 请求。

您的操作是 POST,但不用于路由。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    • 2011-05-19
    • 1970-01-01
    相关资源
    最近更新 更多