简体   繁体   中英

Is it possible to pass more than one complex type parameter separately in the web API 2 Controller post method?

I know [FromBody] allows only one complex type as a parameter. I just wanted to know, is there any other way to do so? Any help or knowledge would be greatly appreciated: Thanks! :)

  1. This is my controller
public HttpResponseMessage Post([FromBody]  List<TranInOutDtl> tranInOutDtl, List<TranInOutDtlsub> tranDtlSub, List<TranInOutDtlsub> tranDtlSub)
  1. This is my complex object below
        public partial class TranInOutDtl
        {
        public int Tranno { get; set; }
        public int Trannosub { get; set; }
        public string ProdTypeDesc { get; set; }
        public string BatchNo { get; set; }
        public string Itemno { get; set; }
        public string ItemDesc { get; set; }
        public decimal ScanPendQty { get; set; }
        public int TotalBoxqty { get; set; }
        public decimal Quantity { get; set; }
        public int BoxQty { get; set; }
        public bool Isdone { get; set; }
        public int PKId { get; set; }
        public int PKSubId { get; set; }
        public string PkBxDesc { get; set; }
        public int BoxSz { get; set; }
        }

        public partial class TranInOutDtlsub
        {
        public int Tranno { get; set; }
        public int Trannosub { get; set; }
        public int Trannosub1 { get; set; }
        public string RackShlvNo { get; set; }
        public string ShlvNo { get; set; }
        public int ShlvBoxQty { get; set; }
        public decimal Quantity { get; set; }
        public int BoxQty { get; set; }
        public bool Isdonesub { get; set; }
        public string RkShlvSelType { get; set; }
        public string RkShCatUId { get; set; }
        public string RackCatDesc { get; set; }
        public string RkShCatColorCode { get; set; }
        }

        public partial class TranInOutRackScan
        {
        public int Tranno { get; set; }
        public int Trannosub { get; set; }
        public int Trannosub1 { get; set; }
        public int Srno { get; set; }
        public string BarcodeNo { get; set; }
        public decimal Quantity { get; set; }
        public int BoxQty { get; set; }
        public string InOut { get; set; }
        public int PackMaster_ID { get; set; }
        public int Pack_type_ID { get; set; }
        }

As it was mentioned by DavidG you could create any complex types that will suit your specific needs so for example

public class TranInOutContainer 
{
    public List<TranInOutDtl> TranInOutDtl Dtl {get; set;}
    public List<TranInOutDtlsub> TranDtlSub DtlSub {get; set;} 
    ....
}

will be valid solution for your problem

You could also use dynamic type ofc but it should be used only if no other solution exists

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM