Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs Pass data has list data

I want to pass data what has list of child like here

{
 id : 1,
 title : 'test',
 childs : [
    { id : 1, name: 'name1' },
    { id : 2, name: 'name2' },
    { id : 3, name: 'name3' }]
}

I want it pass to web api controller

public IHttpActionResult Post(Batche model){
     return model;
}

and batch

 public class Batche
 {
     public long Id { get; set; }
     public string title{ get; set; }
     public ICollection<BatchDetail.BatchDetail> BatchDetails { get; set; }
 }

and batch details

public class BatchDetails(){
      public long Id { get; set; }
      public string Name{ get; set; }
}

when I post data get me null

$http({
   method : 'POST',
   url : baseUrl + "api/MyController",
   data : $scope.model
})
like image 492
Hadi Jahangiri Avatar asked Apr 20 '26 09:04

Hadi Jahangiri


1 Answers

Use [FromBody] before your method parameter

public IHttpActionResult Post([FromBody]Batche model){
like image 77
Pankaj Parkar Avatar answered Apr 21 '26 23:04

Pankaj Parkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!