I have been able to properly bind a complex object to my model from a form but I am struggling for one item in particular and it is not making sense why it wont work as I have repeated the same logic for other examples to this one so I am scratching my head why this isnt working as expected. My axios request is as follows:
const submit = () => {
let form = new FormData();
//state details
form.append('state_details.state_id' , JSON.stringify(stateModel.value!.state_id!))
programModel.value!.forEach((program : Program, index : number) => {form.append('state_details.program_details['+index+'].program_dd', JSON.stringify(program.program_dd))})
stateContactModel.value!.forEach((stateContact : User, index : number) => {form.append('state_details.state_contacts['+index+'].internal_user_number', JSON.stringify(stateContact.internal_user_number))})
//actuarial firm details
form.append('actuarial_firm_details.firm_dd' , JSON.stringify(actuarialFirmModel.value!.firm_dd))
form.append('actuarial_firm_details.actuary_details' , hasRiskMitigationModel.value.value)
signingActuaryModel.value!.forEach((actuary : User, index : number) => {form.append('actuarial_firm_details.signing_actuaries['+ index +'].internal_user_number', JSON.stringify(actuary.internal_user_number))})
api.post('/CertificationReview', form, config).then(response => {
})
}
My models are as follows:
public class AddCertificationReviewDTO
{
[ModelBinder(Name = "state_details")]
[Required]
public required StateDTO StateDetails {get; set;}
[ModelBinder(Name = "actuarial_firm_details")]
[Required]
public required ActuarialFirmDTO ActuarialFirmDetails {get; set;}
}
public class ActuarialFirmDTO
{
[ModelBinder(Name = "firm_dd")]
[Required]
public required int FirmDd {get; set;}
[ModelBinder(Name = "firm_name")]
public string? FirmName {get; set;}
[ModelBinder(Name = "actuary_details")]
[Required]
[Length(1, int.MaxValue, ErrorMessage = "Please enter atleast 1 signing actuary.")]
public required List<UserDTO> ActuaryDetails {get; set;}
}
public class UserDTO {
[ModelBinder(Name = "internal_user_number")]
[Required]
public required int InternalUserNumber {get; set;}
}
public class StateDTO {
[ModelBinder(Name = "state_id")]
[Required]
public required int StateId {get; set;}
[ModelBinder(Name = "entity_name")]
public string? EntityName {get; set;}
[ModelBinder(Name = "entity_abbreviation")]
public string? EntityAbbreviation {get; set;}
[ModelBinder(Name = "program_details")]
[Required]
[Length(1, int.MaxValue, ErrorMessage = "Please enter atleast 1 program.")]
public required List<ProgramDTO> ProgramDetails {get; set;}
[ModelBinder(Name = "state_contacts")]
[Required]
[Length(1, int.MaxValue, ErrorMessage = "Please enter atleast 1 contact.")]
public required List<UserDTO> StateContacts {get; set;}
}
public class ProgramDTO {
[ModelBinder(Name = "program_dd")]
[Required]
public required int ProgramDD {get; set;}
[ModelBinder(Name = "program_name")]
public string? ProgramName {get; set;}
[ModelBinder(Name = "program_short_name")]
public string? ProgramShortName {get; set;}
}
I have followed the same logic for my actuarial firm model as i did for my state by appending the array to the form and it works for state contacts and programs but when i get to my actuarial firm model it fails always saying request failed in the response
"errors": {
"actuarial_firm_details.actuary_details": [
"Please enter atleast 1 signing actuary."
]
}
The models are setup exactly the same so unsure why it wouldnt work.