从另一个控制器调用的WebAPI控制器 [英] Call WebApi controller from another controller
问题描述
所以,我有我的解决方案两个项目。两者都是的WebAPI。我有两个控制器,我可以从客户端调用它们 - 的JavaScript。
问题是,我需要在第一个项目的控制器来调用第二个项目的控制器的方法,从方法。我也觉得我应该指出,我需要调用该方法后,所以我需要把它参数以及。
这是可能的呢?我听说过RedirectToAction的方法,但我认为这不会的WebAPI工作。
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.
推荐答案
您应该不需要张贴到第二个控制器。
You should not need to POST to the second controller.
在项目中创建一些共享code和有两个控制器使用。如果您有需要在第一控制器中的POST变量,你可以简单地传递这些到共享的方法。
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.
这篇关于从另一个控制器调用的WebAPI控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!