Once upon a time in Web Api 2 I could write such an action:
public class INP { public string value { get; set; } } public string Post(INP con) { return con.value; } and everything worked fine with both ContentType: application/x-www-form-urlencoded sent from the client and ContentType: application/json .
However, in asp.net core everything is not so simple: with the above code ContentType: application/x-www-form-urlencoded works, but ContentType: application/json leaves me just null in the code. If you frame the parameter with the [FromBody] attribute, then the situation changes: everything is fine with ContentType: application/json , but with ContentType: application/x-www-form-urlencoded I get an answer like 415 Unsupported Media Type .
So, the question itself: how to write an action in asp.net core, which would take me to the parameter of different ContentType , as it was in Web Api 2? And why has the behavior changed?