0

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?

1
  • Why do you need two views for this? Can't you use something like jqueryui.com/tabs ? Commented Dec 9, 2013 at 15:15

2 Answers 2

6

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");
}
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@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.
3

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.