0

I have two Web APIs built using .Net Core 3.1

I am trying to pass a model which has 2 different Lists as properties. Though the method in the 2nd API is called successfully from the 1st API, the properties of the model i.e. lists are null.

There is no issue with the API call as i could pass and receive the value when i called a method with a string as input parameter.

Here is my code

1st API method :

public async Task SomeMethod(MyModel Input, string resource)
{
   var client = new ServiceClient(BaseUrl)
        {
            Resource = resource,
        };
   client.Post(Input);
} 

resource here is the url for 2nd API Method

Model :

public class MyModel
{
  public List<Class1> List1;
  public List<Class2> List2;
}

2nd API:

    [Route("v1/myservice")]
    [ApiController]
    public class MyController : ControllerBase
    {
        private readonly IMyHandler _myHandler;
        private readonly ILogger _logger;
        private string _MyDestinationPath;
        public  MyController (IMyHandler myHandler, IConfiguration configuration, ILogger logger)
        {
            _myHandler= myHandler;
            _MyDestinationPath = configuration.GetValue<string>("DestinationPath");
            _logger = logger;
        }
        [HttpPost, Route("API2Method"), ResponseType(typeof(string))]
        public async Task API2Method([FromBody]MyModel Input)
        {
            if(!ModelState.IsValid)
            {
                return;
            }
        }
}

Can someone point out what i need to change to receive the lists i am passing to the 2nd API instead of null

WorksOnMyLocal
  • 1,617
  • 3
  • 23
  • 44

1 Answers1

0

We have already answer for this question, Please refer the following urls for this issue.

https://stackoverflow.com/questions/24874490/pass-multiple-complex-objects-to-a-post-put-web-api-method

For more help on parameter passing, Please refer this basic article

https://learn.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api#using-frombody