Call WebApi controller from another controller

一世执手 提交于 2019-12-10 21:53:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/24485765/call-webapi-controller-from-another-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!