Y
Y
YoppaLotus2019-11-05 09:54:38
ASP.NET
YoppaLotus, 2019-11-05 09:54:38

Why does [FromBody] deserialize data into properties and not fields?

For example, there is a controller accepting stringfy json

public ViewResult Insert([FromBody]InsertGroup json)
        {
             //Some code
        }

And the class in which the deserialization takes place
public class InsertGroup
    {
        public int[] selnames { get; set; }
        public string template { get; set; }
    }

If instead of auto-properties there are regular fields, the data simply will not be recorded. Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2019-11-05
@YoppaLotus

I suspect it has something to do with reflection. In any case, you can see the source code and create your own binding.
PS why don't you like the properties?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question