Is it possible for a single action method to render two different views subsequently. And if possible pick the user input from the first view and use it on the second view?
2 Answers
Yes, completely possible. And, it can be multiple views, or even a FileResult or other result type.
public ActionResult MyAction() {
if(/*logic here*/)
return View("ViewOne");
else
return View("ViewTwo");
}
2 Comments
Jude
Little more complicated. ViewOne will send a parameter(post or link) back to the action method and then the parameter will be sent to "ViewTwo" by the method.
Steven V
@Jude You can pass in differing ViewModel's depending on your view's needs. You can create a new ViewModel for ViewOne, then a different ViewModel for ViewTwo within the same action.
Yes, it's possible. Just make sure your views have same view model.
To switch between views you can specify parameter:
return View("MyFirstView", viewModel);
or
return View("MySecondView", viewModel);
1 Comment
Steven V
From a technical stand point, views don't have to have the same view model implemented within the same action. There's just as long as the controller passes in the expected type. If you should have differing view model types within one action, that's a different debate.