Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call WebApi controller from another controller

So I have two projects in my solution. Both are WebApi. I have controllers in both and I can call them from the client side - javascript. The problem is that I need to call a method in the controller of the second project from method in the controller of the first project. I also think I should state that the method I need to call is Post so I need to send it parameters as well. Is this possible at all? I heard about "RedirectToAction" method but I think this won't work in webapi.

like image 308
Binev Avatar asked Jun 19 '26 12:06

Binev


1 Answers

You should not need to POST to the second controller.

Create some shared code in your project and have both controllers use this. If you have the variables needed for a POST in the first controller, you can simply pass these to the shared method.

like image 111
ChrisBint Avatar answered Jun 21 '26 03:06

ChrisBint



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!