I have this action on a .Net Core Web API Controller called HomeController:
[HttpPost]
public IActionResult TestMethod([FromForm] DocumentDto xml) {
int abc = 0;
return Ok();
}
and the model DocumentDto:
[XmlRoot(ElementName = "document", Namespace = "")]
public class DocumentDto
{
[XmlElement(DataType = "string", ElementName = "id")]
public string Id { get; set; }
[XmlElement(DataType = "string", ElementName = "content")]
public string Content { get; set; }
[XmlElement(DataType = "string", ElementName = "author")]
public string Author { get; set; }
}
I have also added a breakpoint on the int abc = 0; and I use Postman to hit the action as displayed below
The xml used for the request is the following
<document>
<id>12345</id>
<content>This is a Test</content>
<author>vchan</author>
</document>
However, during debugging the xml variable has null properties as shown below
Also, on the Startup.cs file I have included the AddXmlSerializerFormatters() and it is as below:
services
.AddMvc()
.AddXmlSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
Why is the xml not parsed?



xmlfile but a string in the request body which should be decoded asxml.