Http post request FromBody string always binding null in dotnet
[HttpPost] public string Book([FromBody] string test) // binding string always is null { return test; }
When having [FromBody]attribute, the string sent should not be a raw string, but rather a JSON string as it includes the wrapping quotes:
'test string' or "test string"
JSON.Stringify('test string') // will be => "test string"
let x= JSON.stringify(JSON.stringify('test string')) // will be => '"\\"test string\\""'
export const isJsonString = (str: string) => { try { JSON.parse(str); } catch (e) { return false; } return true; };