Reputation: 2206
Error CS0029 Cannot implicitly convert type 'Microsoft.Net.Http.Headers.MediaTypeHeaderValue' to 'System.Net.Http.Headers.MediaTypeHeaderValue'
I am in .net Core,
the code:
[HttpGet]
public HttpResponseMessage GetCompanies()
{
var resp = new HttpResponseMessage { Content = new
StringContent("[{\"Name\":\"ABC\"},[{\"A\":\"1\"},{\"B\":\"2\"},
{\"C\":\"3\"}]]", System.Text.Encoding.UTF8, "application/json") };
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return resp;
}
Upvotes: 2
Views: 1370
Reputation: 247471
Core does not use HttpResponseMessage
on the server side. You need to update your syntax.
[HttpGet]
public IActionResult GetCompanies() {
var json = "[{\"Name\":\"ABC\"},[{\"A\":\"1\"},{\"B\":\"2\"},{\"C\":\"3\"}]]";
return Content(json, new MediaTypeHeaderValue("application/json"));
}
Upvotes: 1