Remove <ArrayOf. From MVC Web Api response Remove <ArrayOf. From MVC Web Api response xml xml

Remove <ArrayOf. From MVC Web Api response


Try using the XmlSeriazlier instead:

config.Formatters.XmlFormatter.UseXmlSerializer = true;

And then try defining a class that derives from the collection of Product, and use [XmlRoot("Products")] to rename the element name from 'ArrayOfProduct' to 'Products'.

For example, instead of using List, use the class Products:

[XmlRoot("Products")]public class Products : List<Product> { }public class Product{    public int Id { get; set; }    public string Name { get; set; }    public string Category { get; set; }    public double Price { get; set; }}

ApiController's action:

    public Products Get()    {        return new Products()        {            new Product()             {                Id = 1,                Name = "Tomato Soup",                 Category = "Groceries",                Price = 1            }        };    }