[英]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.