Home > Software design >  controller misinterprets input?
controller misinterprets input?

Time:10-31

I have this controller

public async Task<ActionResult> SubmitFormAsync([FromBody] Dictionary<string, string> input, Guid formGuid)

for which I via postman provide the input

{
  "input": {
    "firstname": "Toren",
    "jobtitle": "Activist",
    "lastname": "SO",
    "message": "",
    "phone": " 123455667"
  }
}

but I keep getting this error in postman

{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "00-79f401cda7f4cdb640dbd8c95dc851d5-a6b4228c3e1675ba-00",
    "errors": {
        "input": [
            "The input field is required."
        ],
        "$.input": [
            "The JSON value could not be converted to System.Collections.Generic.Dictionary`2[System.String,System.String]. Path: $.input | LineNumber: 1 | BytePositionInLine: 12."
        ]
    }
}

I know it means that my input is wrong, but why is it wrong I cannot figure out.

CodePudding user response:

You need to post the body, without key as below --

{
    "firstname": "Toren",
    "jobtitle": "Activist",
    "lastname": "SO",
    "message": "",
    "phone": " 123455667"
  }

and pass the guid in query string.

  • Related