WebAPI routing: single string parameter
<p>So, according to <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api" rel="nofollow noreferrer">this</a>:</p>
<blockquote>
<ul>
<li>If the parameter is a “simple” type, Web API tries to get the value
from the URI. Simple types include the .NET primitive types (int,
bool, double, and so forth), plus TimeSpan, DateTime, Guid, decimal,
and string, plus any type with a type converter that can convert from
a string. (More about type converters later.)</li>
<li>For complex types, Web
API tries to read the value from the message body, using a media-type
formatter.</li>
</ul>
</blockquote>
<p>I have a <code>POST</code> action with a single <code>string</code> parameter coming from the user's input and can therefore be any character - foreign, unicode, apostrophe, '%20' etc. anything!</p>
<p>I am therefore reluctant to have this parameter in the URL and the <code>[FromBody]</code> decorator doesn't appear to be helping. Question is: what is the best [<em>a-hem</em>] pratice for posting a single string parameter to WebAPI controller?</p>
<p>C#:</p>
<pre><code>[HttpPost]
[Route(&quot;api/add&quot;)]
public void Add([FromBody]string name)
{
    // name is null :(
}
</code></pre>
<p>JS:</p>
<pre><code>function add(name: string) {
    return this.$http.post(&quot;api/add/&quot;, name);
}
</code></pre>
<p><a href="https://i.stack.imgur.com/QgVL1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QgVL1.png" alt="enter image description here" /></a></p>