1

The question "How to call another controller Action From a controller in Mvc" has some good answers, but it would seem things have changed. The answer

var controller = DependencyResolver.Current.GetService<ControllerB>();
controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);

doesn't work in mvc core because DependencyResolver and a 2 param ControllerContext constructor no longer exist.

What is the new way to do this?

I don't want to redirect. I don't want to loose the controller context.

Cory-G
  • 960
  • 14
  • 23
  • Looks like I can inject `controller2` into `controller1`'s constructor by adding `AddControllersAsServices` to the startup. I can also pass it in using `[FromServices]` on the individual endpoint. I don't know if that gives me an isolated controller, though. Also, I still don't know how to set it's context... – Cory-G Sep 20 '18 at 23:47

1 Answers1

0

I got my application working - so far - with this trick:

var useController = new ControllerB(); useController.ControllerContext = new ControllerContext(this.ControllerContext);

As you see - much simpler, and at least AUTH worked.

lewis
  • 439
  • 6
  • 22