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).
How to display body as html forms using Swagger in ASP.NET Core

In Swagger my UI looks like, ideally Id would also not be a required input as it is auto-generated.
How to display body as html forms using Swagger in ASP.NET Core

From the request body drop down box I only have these choices.
How to display body as html forms using Swagger in ASP.NET Core

Any help much appreciated.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x