【发布时间】:2011-07-20 15:53:30
【问题描述】:
在 ASP.NET MVC 中,我有一个看起来像这样的控制器:
public class MyController{
public ActionResult Index(){
return View(new MyModel());
}
[HttpPost]
public ActionResult Index(MyModel model){
//do something
return View("RegistrationConfirmation", new ConfirmModel());
}
[HttpPost]
public ActionResult RegistrationConfirmation(ConfirmModel model){
//do something else
return View();
}
}
我想要的用户工作流程如下
-
GET页面索引。返回视图Index。网址:~/My -
POST来自索引页面的数据 - 返回视图RegistrationConfirmation并将用户发送到右侧页面~/My/RegistrationConfirmation。 - 在
RegistrationConfirmation页面上用户POSTs 另一个数据,以便调用RegistrationConfirmation来处理它们。
现在操作方法RegistrationConfirmation 永远不会被调用,因为在通过索引操作方法返回RegistrationConfirmation 视图后,URL 保持在~/My,所以第二个帖子由Index(MyModel) 操作方法而不是RegistrationConfirmation(ConfirmModel) 操作方法处理。
如何在发送视图的同时更改 URL,以便在 POST back 上调用与视图对应的控制器操作?或者有没有其他方法可以确保调用对应的控制器?
注意:在发布此问题之前,我已经阅读了 20 多个似乎与主题相关的问题。我不认为对其中任何一个的完美答案会给我解决方案。请在投票结束前正确阅读重复。
【问题讨论】:
-
Html.Action 方法应该让您灵活地选择要调用的正确操作方法?
标签: c# asp.net asp.net-mvc url redirect