Is it possible to change URL when returning View in the same time ? That is without redirecting?
In ASP.NET MVC I have a controller that looks somehow like this:
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();
}
}
User's workflow that I'd like to have is following
GET
page index. Returns viewIndex
. URL:~/My
POST
data from Index page - returns viewR开发者_JS百科egistrationConfirmation
and send the user to right page~/My/RegistrationConfirmation
.- User
POST
s another data while onRegistrationConfirmation
page so thatRegistrationConfirmation
gets called to process them.
Right now action method RegistrationConfirmation
is never called because after returning RegistrationConfirmation
view by Index action method URL stays ~/My
so the second post is processed by Index(MyModel)
action method not by RegistrationConfirmation(ConfirmModel)
action method.
How can I change URL along with sending the View so that the controller action that corresponds to the view gets called on POST
back ? Or is there any other way how to ensure that corresponding controller is called?
NOTE: I have really read more than 20 questions that seemed to be on topic before posting this one. I don't think perfect answer to any of them will give me solution. Please read properly before voting to close as duplicate.
try this one in the view RegistationConfirmation
you can easily add the action and the controller which should be targeted in the Html.BeginnForm command...
<% using(Html.BeginForm("RegistrationConfirmation", "MyController")){%>
//form elements
<%}%>
with this you exactly define which action and controller is going to be called
精彩评论