Question: Can we bind without the use of a model and just purely based on the parameter names of the IActionResult method. From the below I am posting a single string to the end point, however it is wrapped in a object with a property of reviewNotes. I have a work around at the moment, which is explained below.
I have setup the end point llike so.
[HttpPost("updateassetnotes/{id}")]
public IActionResult UpdateAssetNotes(int id, [FromBody]string reviewNotes)
{
_dataMapper.UpdateAssetNotes(id, reviewNotes);
return ApiSuccess("Updated Review Notes");
}
And the client side is posting like this.
var url = "/api/cataloguing/updateassetnotes/" + id;
var data = { reviewNotes: self.assetReviewNotes() };
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(data),
contentType: 'application/json'
}).done(function (resp) {
}).fail(function (resp) {
}).always(function () {
});
However if I change the data to:
var data = self.assetReviewNotes();
Then the review notes string is actually populated. As mentioned this is the work around im using at the moment. As previously mentioned I could create a simple model like the below and use this in the end point to bind the string. Im just wondering if there is a way to bind directly to the primitive types.
public class SimpleModel {
public string ReivewNotes {get;set;}
}
JSON.stringifydata object with no name? With stringify request looking{"reviewNotes":"sss"}and withoutreviewNotes=sss