How to display body as html forms using Swagger in ASP.NET Core

In Swagger is it possible to have the body represented as HTML forms as opposed to a JSON string? and how would one achieve this?

In django for example I can input the JSON via html forms (Yes this is a simple example, but more complex objects can be a little annoying to write JSON, especially where the field is a foreign key and you can't remember the entries in that table). enter image description here

In Swagger my UI looks like, ideally Id would also not be a required input as it is auto-generated. enter image description here

From the request body drop down box I only have these choices.
enter image description here

Any help much appreciated.

1 answer

  • answered 2021-01-18 00:24 Soggy

    As Andy correctly noted in the comments the answer is to add the [FromForm] annotation to the argument in the endpoint function

    enter image description here