Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Subarray object cannot update (HttpPut)

$
0
0

Hi folks,

here is my object:

{"userID": 18,"firstName": "bob","lastName": "smith","age": 22,"education": [
        {"eduID": 7,"teacher": "Kane","course": "Math",
        },
        {"eduID": 8,"teacher": "John","course": "Biology",
        }
    ]
}

I can update first name or last name but  cannot update education as subarray e.g teacher or course. 

 [HttpPut("{id}")]
 public async Task<IActionResult> PutPerson([FromRoute] int id, [FromBody] Person person)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }

     if (id != person.userID)
     {
         return BadRequest();
     }

     _context.Entry(person).State = EntityState.Modified;

     try
     {

         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
        ........
     }

     return NoContent();
 }

Any idea?
I am waiting for your response
Thanks in advance

 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>