I have a web api where the global configuration is configured to use: XmlMediaTypeFormatter
My problem is that I want to extend this web api with a new controller that uses JsonMediaTypeFormatter instead.
Is it possible to change MediaTypeFormatter to JSON for only one API controller class?
My problem is not returning JSON, I added this with returning HttpResponseMessage:
return new HttpResponseMessage { Content = new ObjectContent<string>("Hello world", new JsonMediaTypeFormatter()), StatusCode = HttpStatusCode.OK };
Upon request, I get this problem. If I have an object with two properties:
public class VMRegistrant { public int MerchantId { get; set; } public string Email { get; set; } }
And my controller action takes VMRegistrant as an argument:
public HttpResponseMessage CreateRegistrant(VMRegistrant registrant) {
But the problem is when I call the action with JSON, it fails.
source share