0

I have the react snippet:

const model = {
    Code: 'somecode',
    Elements: elements,
    ...more
}

apiPost(url, false, model)
        .then(
)

Then:

export function apiPost(url, addAuth, json) {
    return apiFetch('post', url, addAuth, json)
}



function apiFetch(method, url, addAuth, json, file) {

let opts = {
    method: method,
    headers: {}
}

if (addAuth) {
    opts.headers = { ...opts.headers, ...authHeader() }
}

if (json) {
    opts.headers = { ...opts.headers, ...{ 'content-type': 'application/json' } }
    opts.body = JSON.stringify(json);
}

if (file) {
    opts.body = file;
}

return fetch(baseUrl() + url, opts).then(handleResponse)

}

I am receiving it at the api side:

    [HttpPost]
    public async Task<JsonResult> Post([System.Web.Http.FromBody] SurveyEntry model)
    {
        try
        {
            ...
        }
        catch (Exception ex)
        {
            ...
        }
    }

but the model comes null.

I am puzzled why this happens.

Any suggestions what I am doing wrong?

nickornotto
  • 1,946
  • 4
  • 36
  • 68
  • 1
    When you send the POST request, can you see the request payload in Chrome's network tab? If the `model` is in the request payload, then it is probably a backend problem. – mtbno Jan 09 '21 at 16:45
  • That I can see - that's why I'm asking what could be wrong with the current action that it's not picking up the json model? – nickornotto Jan 18 '21 at 09:59

0 Answers0