C# MVC RedirectToAction正在重定向到其他方法
在我的控制器中,我有三种方法:C# MVC RedirectToAction正在重定向到其他方法,c#,asp.net-mvc,C#,Asp.net Mvc,在我的控制器中,我有三种方法: public ActionResult DisplayPostsComments() { var viewModel = new DisplayPostsCommentsWiewModel(); return View(viewModel); } [HttpPost] public ActionResult DisplayPostsComments(DateTime start, Date
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 });
}
}
使用参数调用第二个方法。但是我实现了对第一个方法的调用。我做错了什么?重定向将302重定向响应返回给客户端,迫使客户端向提供的位置发出GET请求
您的操作是POST,但不用于路由。为什么不调用DisplayPostsComments方法本身?请注意,模型视图控制器标记用于询问有关模式的问题。ASP.NET-MVC实现有一个特定的标记。
return RedirectToAction("DisplayPostsComments", new { start = start, end = end });