31

I have a controller action which I would like to call another controller action.

Is this a valid thing to do. Is it possible?

1

2 Answers 2

31

Controller.RedirectToAction

Sign up to request clarification or add additional context in comments.

7 Comments

This is issuing an HTTP 302 content redirect, involving a browser round trip. Is there a way to get rid of the round trip?
Controller actions are publicly visible HTTP endpoints. If you have two actions which need to do the same things, then what you need is either a set of nonpublic controller methods or a set of services.
inside the controller that you are calling enter return View("viewName", object); inside the other controller call return <controller>(params...)
Could you explain more about the services solution?
why dont you just create an instance of that controller object and call the method? This is a simple OOP solution and doesnt require you to do any redirecting...
|
6

As @Justice says you can use RedirectToAction. Also, you can use TempData to pass model (and other) data between controller actions.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.