Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi Guys,
I've got a simple api controller like so:
public class MailingListApiController : UmbracoApiController
{
public string GetAllRecipients()
return Json.Encode(new string[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" });
}
in my app_start folder I have webapiconfig.cs:
public static class WebApiConfig
public static void Register(HttpConfiguration config)
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
which removes the XML formatter
i have checked that it is called in global.asax
But my controller is still returning xml.. just wondering if anyone could suggest how to get this working..
Cheers
Hi,
try this:
public HttpResponseMessage ControlleName()
string json = "some content";
return new HttpResponseMessage() { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
ApiController Return Json
Hi Guys,
I've got a simple api controller like so:
public class MailingListApiController : UmbracoApiController
{
public string GetAllRecipients()
{
return Json.Encode(new string[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" });
}
}
in my app_start folder I have webapiconfig.cs:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
}
which removes the XML formatter
i have checked that it is called in global.asax
But my controller is still returning xml.. just wondering if anyone could suggest how to get this working..
Cheers
Hi,
try this:
public HttpResponseMessage ControlleName()
{
string json = "some content";
return new HttpResponseMessage() { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };
}
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.