I'm trying to post XML to asp.net core 2:
$.ajax({
type: "POST",
url: 'api/Test',
data: "<test>hello<test>",
contentType: "application/xml",
success: function (response) { alert(response); },
});
How should I write the action, so it accepts the xml as parameter?
IActionResult Post([FromBody]string xml)-> xml is nullIActionResult Post([FromBody]XElement xml)-> xml is nullIActionResult Post(XElement xml)-> InvalidOperationException: Could not create an instance of type 'System.Xml.Linq.XElement'. Model bound complex types must not be abstract or value types and must have a parameterless constructor.IActionResult Post(string xml)-> xml is null
in the Startup.ConfigureServices:
services.AddMvc()
.AddXmlSerializerFormatters();
How to write the controller so that it accepts XML as a parameter? I know I can read it from HttpContext.Request, but I want it to be parameter