I have a simple API I am writing which includes a POST method to insert a new record into a couple of database tables. The data is coming from form data.
One of the items is a collection which includes a few fields.
I am using Swagger to test and when I Post the form data the collection field is blank.
Controller - Post endpoint
[HttpPost("addboardmember")]
public IActionResult PostBoardMember([FromForm] MemberForm memberData)
{
try
{
_memberRepository.PostBoardMember(memberData);
var newMember = _memberRepository.GetMembers().SingleOrDefault(m => m.SSN == memberData.SSN);
var newMemberId = newMember.Member_ID;
var boardArray = memberData.BoardForms;
return Ok();
//return Ok() is temporary, will return 201 with appropriate data
}
catch (Exception ex)
{
return BadRequest("Couldn't Save record??" + ex.InnerException.ToString());
}
}
MemberForm class (Abbreviated to highlight the main fields and the field I am struggling with populating: BoardForms
public class MemberForm
{
[Required, NotNull]
public string LastName { get; set; }
[Required, NotNull]
public string FirstName { get; set; }
[Required, NotNull]
public string SSN {get; set;}
public virtual ICollection<BoardForm> BoardForms { get; set; }
}
}
BoardForm class:
public class BoardForm
{
public int Board_ID { get; set; }
public int StartYear { get; set; }
public int EndYear { get; set; }
}
When I test Post API endpoint using Swagger the BoardForms field has a count of zero.

Swagger input.
I will have additional business logic to create a record based on each record in the BoardForm array.
I do not know how I am supposed to access the array being sent in the Form Data which is setup as an ICollection.
Browser Developer Tools payload:

All the elements shown above in the payload screenshot are mapped to their correct elements an I can see the values with the exception of the 'BoardForms' array.
