What is the best way to consume WebAPI service from ActionResult in another controller?
Basicaly i have a controller that returns the data.
public class MyApiController : ApiController
{
public MyData Get()
{
//returns the data
}
}
and i want to consume this data from
public class MyConsumeController: Controller
{
public ActionResult MyConsumeAction()
{
var something = //Call Get inside MyApiController
}
}
Any ideas?
Note: I know how to consume it using HttpClient (different project) or jquery (from views).
You could use the client API – the HttpClient class. And here’s another sample.