How to do it...

  1. First, let's add the following dependency in the project:
"Microsoft.AspNetCore.MVC.Formatters.Xml": "2.0.0"
  1. Next, let's add the following code to the ConfigureServices method of Startup.cs:
services.AddMVC(options =>{  options.RespectBrowserAcceptHeader = true;  options.InputFormatters.Add(  new XmlDataContractSerializerInputFormatter());  options.OutputFormatters.Add(  new XmlDataContractSerializerOutputFormatter());});
  1. Finally, we can see the list of products in the XML format:

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.