renee Nay

renee Nay

  • 2k
  • 24
  • 138

reading Json and Xml

Apr 15 2021 2:20 PM
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<BatchData> Get()
        {
            List<BatchData> cancel = new List<BatchData>
                {
                    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;
            }
        }
    ]

Answers (6)