Info
Version: | 1.1.1 |
Author(s): | YouZack |
Last Update: | Tuesday, March 2, 2021 |
.NET Fiddle: | Create the first Fiddle |
Project Url: | https://github.com/yangzhongke/YouZack.FromJsonBody |
NuGet Url: | https://www.nuget.org/packages/YouZack.FromJsonBody |
Install
Install-Package YouZack.FromJsonBody
dotnet add package YouZack.FromJsonBody
paket add YouZack.FromJsonBody
YouZack.FromJsonBody Download (Unzip the "nupkg" after downloading)
Dependencies
- Microsoft.AspNetCore.Http(>= 2.2.2)
- Microsoft.AspNetCore.Http.Abstractions(>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Abstractions(>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core(>= 2.2.5)
- System.Text.Json(>= 4.7.1)
Bind simple parameter of Action with HttpBody of Json format.
For ASP.Net Core MVC and ASP.Net Core WebAPI
···
public async Task<IActionResult> Test([FromJsonBody]string phoneNumber, [FromJsonBody]string test1,
[FromJsonBody]int? age, [FromJsonBody] bool gender, [FromJsonBody] double salary);
···
Http Body:
{"phoneNumber":"110112119","age":18,"gender":true}
and ContentType of request should be application/json
Add following code to Startup before app.UseEndpoints():
···
app.UseFromJsonBody();//using YouZack.FromJsonBody;
···
Done!
To KEEP IT SIMPLE, YouZack.FromJsonBody only supports simple parameter types,like int,long,double,bool,Enum,string ,but does not support complex types,like Array,List,POCO etc.
If you want to use complex types, please go backwards to '[FromBody]' and ModelBinder.