[英]Is it possible to change URL when returning View in the same time ? That is without redirecting?
在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
。 POST
在RegistrationConfirmation
页面上的另一个数据,以便调用RegistrationConfirmation
来处理它们。 现在动作方法RegistrationConfirmation
从不被调用,因为在通过索引操作方法返回RegistrationConfirmation
视图后,URL保持~/My
所以第二个帖子由Index(MyModel)
动作方法处理,而不是由RegistrationConfirmation(ConfirmModel)
动作方法处理。
如何更改URL以及发送View以便在POST
后调用与视图对应的控制器操作? 或者还有其他方法可以确保调用相应的控制器吗?
注意:在发布这个问题之前,我确实已经阅读了20多个关于主题的问题。 我认为对他们中任何一个人的完美答案都不会给我解决方案。 请在投票前正确阅读以作为重复结束。
在RegistationConfirmation视图中尝试这个
您可以轻松添加应该在Html.BeginnForm命令中定位的操作和控制器...
<% using(Html.BeginForm("RegistrationConfirmation", "MyController")){%>
//form elements
<%}%>
有了这个,你就可以准确地定义要调用的动作和控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.