I would like to understand why in case when there is only one parameter in the POST body, for content type url-formencoded the syntax is different than in case of multiple parameters.
Let's assume we've got these 2 methods with matching route templates:
public string PostSingleString([FromBody]string value)
{
return value;
}
public class Values
{
public string Value1 {get; set;}
public string Value2 {get; set;}
}
public string PostMultipleStrings(Values values)
{
return String.Format("{0}-{1}", values.Value1, values.Value2);
}
In the first case the request would be:
POST [controller]/
body: =myValue
in the second one though:
POST [controller]/
body: Value1=one&Value2=two
If in the first case the syntax from the second example is used (value=myValue
) the param won't bind (unless the string is wrapped in a complex type).
Can anyone explain why this is the case?