PeteJobi / JsonParametersModelBinder

Map JSON object directly to controller action parameters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NuGet

JsonParametersModelBinder

Allows you to map JSON object directly to controller action parameters. Convert JSON model

{ "a": "a", "b": { "c": "value" } }

directly to action method

public ... Method(string a, dynamic b)

Warning

Nested objects are supported as dynamic types (with limitations).

Usage

Step 1. Add attribute JsonParameters to your action

[HttpPost("two")]
[JsonParameters]
public async Task<IActionResult> TwoParameters(string a, dynamic b)
{
    Console.WriteLine(b.c);
    return Ok();
}

Step 2. Enhoy simplified workflow.

Thanks

Thanks to tchivs for providing code to map to dynamic types

About

Map JSON object directly to controller action parameters

License:MIT License


Languages

Language:C# 100.0%