✅ Binding Nested values in RequestBody to Model
Consider the following model I use inside the MVC structure:
However, when responding to requests, this is instead formatted as
application/hal+json
, which would look like this:
As you can see, the property Url
has been moved into _links:external:href
.
Now I would like to receive a Collection in a [HttpPut]
request, but I'm having trouble figuring out how to properly parse the incoming application/hal+json
to my Model.
I've read online that Model Binding is probably the solution to this, but the vast majority of examples and explanations I could find were centered around Routes / Query parameters, not RequestBody formatting.
The part I did find mentioned ValueProviders, but I couldn't find out how to obtain the JSON data from the body and store it as keys there.
Any suggestions are appreciated, as I'm rather new to MVC architecture and C# in general.1 Reply
It looks like Model Binding is the way to go, but getting the request body's text is more difficult than I thought
it enforces the read to be async, but
IModelBuilder
throws an error even though it's async
Is there another way to obtain it other than bindingContext.HttpContext.Request.BodyReader
?
I seem to have find a way to do it in the model binder: