-2

I have this controller method handling a POST request:

[SharePointContextWebAPIFilter]
[HttpPost]
[ActionName("InviaMailAlProtocollo")]
public IHttpActionResult InviaMailAlProtocollo(string siglaIdUor)
{

    Console.WriteLine("INTO InviaMailAlProtocollo()" + siglaIdUor);

    Console.WriteLine("INTO InviaAlProtocollo()" + siglaIdUor);

    string requestContent = Request.Content.ToString();


    return Ok("TEST");

}

I am performing a POST request passing a JSON document inside the body of the request.

How can I correctly retrieve and print this JSON document inside my controller method?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

1 Answers1

1

First To need To Declare A Data transfer object(DTO) Details Here In your model Folder that looks the same as the json object.

Forexmaple you have a json object looks like this:

{ Id:22, Name:"Ibrahim", Children:["Name1","Name2","Name3"] }

make a corresponding plain old Csharp object(Poco) like the following:

  public class ParentBasicInfo
    { 
    public int Id {get ;set;}
    public string Name{get ;set;}
    public List<string>Children{get ;set;}
    }

in your controller put an instance of your poco:

Replace:

public IHttpActionResult InviaMailAlProtocollo(string siglaIdUor)
{
}

with :

public IHttpActionResult InviaMailAlProtocollo(ParentBasicInfo siglaIdUor)
{
}

all of the json object will be inslide of siglaIdUor

you can access its properties like any object.

Hope that Helps.