What is the best way of calling an action method from another controller?
-
26-05-2021 - |
Frage
What is the best way to invoke an Action-method method in Controller A, from Action-method method in Controller B? Is it true to have such an invocation at all?
Lösung
Best way is by calling return RedirectToAction()
.
But the right way to go will be to move the relevant code from your controllers/actions to an outside place, a service or business logic layer. It's wrong that they reside in your controller, it's not the place, and it now causes you headaches how to jump to another controller and then back. It's just wrong. Instead of finding a way to get around, simply fix your architecture.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow