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;
}
}
]
Jaimin ShethiyaPosted Apr 16, 2021, 1:13 PM
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.
renee NayPosted Apr 15, 2021, 7:37 PM
Rijwan AnsariPosted Apr 15, 2021, 5:12 PM
Rijwan AnsariPosted Apr 15, 2021, 4:59 PM
public BatchData Post([FromBody] BatchData cancel)
{
renee NayPosted Apr 15, 2021, 4:28 PM
Rijwan AnsariPosted Apr 15, 2021, 3:39 PM