I am running this code and it works great ..except when I am reading the xml. it reads the json but not the xml.
I was following the directions in this post Combine XML And Json Requests And Responses In ASP.NET Core Web API .
I am trying to give the user the function to send data in either json or xml.
I don't know how to get it to also read the xml in the post function or what I did wrong
here is my code
[[Route("api/[controller]")]
public class CancelController : Controller
{
[HttpGet("get.{format}"), FormatFilter]
public IEnumerable Get()
{
List cancel = new List
{
new BatchData { BatchNumber = "1"},
new BatchData { BatchNumber = "2"}
};
return cancel;
}
[HttpPost("post.{format}"), FormatFilter]
public BatchData Post([FromBody] BatchData cancel)
{
if (ModelState.IsValid)
{
return cancel;
}
else
{
return cancel;
}
}
]
public class CancelController : Controller
{
[HttpGet("get.{format}"), FormatFilter]
public IEnumerable
{
List
{
new BatchData { BatchNumber = "1"},
new BatchData { BatchNumber = "2"}
};
return cancel;
}
[HttpPost("post.{format}"), FormatFilter]
public BatchData Post([FromBody] BatchData cancel)
{
if (ModelState.IsValid)
{
return cancel;
}
else
{
return cancel;
}
}
]

Rijwan AnsariRank #82 · 24.2K reputationPosted Apr 15, 2021, 11:39 AM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Apr 15, 2021, 1:12 PM EDT
renee Nay22 reputationPosted Apr 15, 2021, 12:28 PM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Apr 15, 2021, 12:59 PM EDT
public BatchData Post([FromBody] BatchData cancel)
{
renee Nay22 reputationPosted Apr 15, 2021, 3:37 PM EDT
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Apr 16, 2021, 9:13 AM EDT
could you please check the below link.
https://andrewlock.net/formatting-response-data-as-xml-or-json-based-on-the-url-in-asp-net-core/#:~:text=You%20want%20to%20be%20able,format%20the%20result%20as%20JSON.
Thanks.