How to make the View returned by the controller and generated by Razor get the data from the api i want to keep the razor engine view and use the api the original mvc cont
The basis of the link supplied by twoflower is to have your handlers create and return an instance of a custom IHttpActionResult implementation. A simplified example is shown below:
public class TestHttpActionResult : IHttpActionResult
{
private readonly HttpRequestMessage _request;
private readonly string _responseString;
public TestHttpActionResult(HttpRequestMessage request, string responseString)
{
_request = request;
_responseString = responseString;
}
public Task ExecuteAsync(CancellationToken cancellationToken)
{
var response = _request.CreateResponse(HttpStatusCode.Created);
response.Content = new StringContent(_responseString);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
return Task.FromResult(response);
}
}