Skip to content

Read json data from web api httppost body #28442

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


So I have a simple requirement to gather logging data from a WASM client into a Web API.

NOTE we are not using Entity Framework...

I have created the following class:

public class EventInformation
{
public string Location;
public string Context;
public int Severity = 1;
}

With a simple web API target:

[Route("[controller]")]
[ApiController]
public class UserStateController : ControllerBase
{

[HttpPost]
[Route("LogEvent")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult LogEvent([FromBody] EventInformation logData)
{
string Context = logData.Context;
string Location = logData.Location;
int Severity = logData.Severity;
return Ok();
}
}

I run it with the swagger.. with this json payload

{
"Context": "hello",
"Location": "world",
"Severity": 0
}

and get...

! [image.png] (https://aka.ms/dc/image?name=B79a6317af1324ab8a880c75970f2ddc7637418511419634176_20201124-164540-image.png&tid=79a6317af1324ab8a880c75970f2ddc7637418511419634176)

Runs to the break point all looks good except where is the data? Doesn't seem t be populating my logData parameter from my JSON body?


Original Comments

Feedback Bot on 11/24/2020, 10:30 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 11/25/2020, 07:19 PM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.


Original Solutions

(no solutions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Author: Migration Bot 🤖The issue was created by a issue mover bot. The author may not be the actual author.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions