I am trying to use fetch from the client side to request a chat session. In my controller I am attempting to capture (or bind) the request body to a model. Then, my controller is using the model to make an API call using RestSharp. The problem is that my parameter is not getting the values of the request body.
Here is how it looks:
// The fetch from the view
const requestBody = buildRequestSession()
var url = '@Url.Action("RequestSession", "Sdk")'
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
body: JSON.stringify(requestBody)
})
This is the payload of the fetch
// Controller action
[HttpPost]
public async Task<IActionResult> RequestSessionAsync([FromBody]RequestSession requestSession)
{
RestRequest request = new RestRequest("sessions");
RestResponse response = await _restClient.ExecuteGetAsync(request);
RequestSessionResponse? sessionResponse = JsonConvert.DeserializeObject<RequestSessionResponse>(response.Content!);
return Json(sessionResponse);
}
This is the result of the fetch:
// model for my controller action parameter
public record RequestSession
{
[JsonProperty("businessUnitName")]
internal string BusinessUnitName { get; set; } = string.Empty;
[JsonProperty("caption")]
internal string Caption { get; set; } = string.Empty;
[JsonProperty("contactData")]
internal ContactData[]? ContactData { get; set; }
[JsonProperty("customerName")]
internal string CustomerName { get; set; } = string.Empty;
[JsonProperty("destination")]
internal string Destination { get; set; } = string.Empty;
[JsonProperty("language")]
internal string Language { get; set; } = string.Empty;
[JsonProperty("priority")]
internal int Priority { get; set; }
[JsonProperty("source")]
internal string Source { get; set; } = string.Empty;
}
My setup: ASP.NET Core 6 MVC web application using Visual Studio 2022.
I understand this may appear to be a duplicate question, however, none of the suggestions in the following posts have resolved my issue.
I have restructured my fetch, model, and controller action in various ways to no avail. All of the suggestions mentioned in other SO posts have not worked. Any explanation on how this is suppose to work will be appreciated.

