Hi I have a view in which I wrote a jquery script to pass a html table values into a JSON object as shown below;
var contactData = [];
$('#tblContacts > tbody > tr').each(function () {
contactData.push({
firstName: $(this).find('input.c-firstname').val(),
lastname: $(this).find('input.c-lastname').val(),
phone: $(this).find('input.c-phone').val(),
email: $(this).find('input.c-email').val()
})
})
Though I left out part of the code above, but I confirmed that contactData
object has the required data. So I got no issues there.
My Challenge: Now I need the object contactData
passed into my controller method to get the values into the database as shown below;
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(CreateBusinessPartnerVM businessPartnerVM)
{
if (ModelState.IsValid)
{
var businessPartner = new BusinessPartner
{
CardCode = prefixCardCode + businessPartnerVM.CardName.ElementAt(0) + DateTime.Now.ToString(),
CardName = businessPartnerVM.CardName,
CardType = businessPartnerVM.CardType,
Email = businessPartnerVM.Email,
Phone = businessPartnerVM.Phone,
IsActive = businessPartnerVM.IsActive,
ContactPersons = //contactData from the jquery script in the view
};
}
}
I have searched and still not found something similar with my requirement. I hope to get a fast help here. Thanks.