title: Post XML to asp.net core 2.0 web api
body: <p>I'm trying to post XML to asp.net core 2:</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: 'api/Test',
      data: "&lt;test&gt;hello&lt;test&gt;",
      contentType: "application/xml",
      success: function (response) { alert(response); },
  });
  </code></pre>
  
  <p>How should I write the action, so it accepts the xml as parameter?</p>
  
  <ul>
  <li><code>IActionResult Post([FromBody]string xml)</code> -> xml is null</li>
  <li><code>IActionResult Post([FromBody]XElement xml)</code> -> xml is null</li>
  <li><code>IActionResult Post(XElement xml)</code> ->
  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.</li>
  <li><code>IActionResult Post(string xml)</code> -> xml is null</li>
  </ul>
  
  <p>in the Startup.ConfigureServices:</p>
  
  <pre><code>services.AddMvc()
      .AddXmlSerializerFormatters();
  </code></pre>
  
  <p>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</p>