MVC .net core : response type always json not xml with ICollection

Viewed 280

I use this contribution for return json or xml depending "Accept" header.

https://docs.microsoft.com/en-us/aspnet/core/mvc/models/formatting

services.AddMvc(options =>
{
    options.RespectBrowserAcceptHeader = true;
    options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
});

My object

public partial class Cartes
{
    public Cartes()
    {

    }

    public string CartNumero { get; set; }
    public int? CartConsId { get; set; }
    public int CartLotcaId { get; set; }
    public int CartTypcaId { get; set; }
    public string CartCrc { get; set; }
    public DateTime? CartDateAttribution { get; set; }
    public DateTime? CartDateClotureCarte { get; set; }
    public DateTime? CartDateSaisie { get; set; }
}

It's Work !

But when I add an ICollection property to Cartes the return is always in JSON !

public virtual ICollection<UtilisationsCriteres> UtilisationsCriteres { get; set; }

UtilisationsCriteres class :

public partial class UtilisationsCriteres
{
    public int UtcriConsId { get; set; }
    public int UtcriCrsupId { get; set; }
    public string UtcriValeur { get; set; }
    public int UtcriPartclieId { get; set; }
    public DateTime UtcriDateInsert { get; set; }
    public DateTime UtcriDateUpdate { get; set; }
    public string UtcriUserUpdate { get; set; }
}

The return type of the controller is IActionResult.

Any idea why ?

1 Answers
Related