1
votes

I am trying to do a PUT Api call and and passing through a object. In the front end, when I console.log the object before performing the API call, it reads the value just fine...

However, when it reaches the breakpoint in the .Net Core controller, the value is always null, no matter what I try.

Angular/Client Side

public edit(message) {
            console.log(message);
            this.$http.put(`api/causemessage`, message).then((res) => {
                this.$state.reload();
            });
        }

.Net Core Controller

[HttpPut]
        public void Put([FromBody] CauseMessage msg)
        {
            _service.EditCauseMessage(msg);
            //TODO : Get the PUT to get the correct data from the client side.  Client side "should" be sending the
            //TODO : correct data already.
        }

^ msg seems to always be null even though before the api call in the client, the log shows it filled with data.

Developers Tools - Console Log

Object {id: 1004, message: "Testing123", messageDate: "Today", causeId: "d5a93ae4-f248-439a-9425-8be7746591fc", $$hashKey: "object:15"}
$$hashKey
:
"object:15"
causeId
:
"d5a93ae4-f248-439a-9425-8be7746591fc"
id
:
1004
message
:
"Testing123"
messageDate
:
"Today"

If anyone can help me find out why I'm always receiving a null value, that would be great.

1
set the content type as json and make sure to JSON.stringyfy the payload when sending itNkosi
I ended up figuring this out.. I needed to make a DTO with the correct parameters in order for the data bind to work.Alex Liosatos

1 Answers

1
votes

Needed to make sure I have a correct DTO to data-bind with. Mine I had was 5 properties instead of the 4 being sent from the client side.

Sorry! but thanks for the answers!