One thing on my mind: 1. Is it necessary for the names to match when transmitting data from client to my webapi controller?
In case my model is structured like this:
public class Donation
{
public string DonorType { get; set; }
//etc
}
But the form on my webpage looks like this:
<div class="button-group grid-x align-center" id='sz-gift-source-group'>
<a class="hollow button cell small-6" id="sz-donate-individual" sz-data-toggle-button required>A family or individual</a>
<a class="hollow button cell small-6" id="sz-donate-corporate" sz-data-toggle-button>A business or company</a>
</div>
Along with an event handler like this:
$('form button[type=submit]').on('click', () => {
const donation = getDonation();
$.post(
'//localhost:61012/api/Donation',
$("#sz-donate-form").serialize(),
(data) => {
console.log(`post succeeded:[${JSON.stringify(data)}]`);
})
.fail((data) => {
console.log(`post failed:[${JSON.stringify(data)}]`);
})
.always((data) => {
console.log(`post complete:[${JSON.stringify(data)}]`);
});
return false;
});
Additionally, how can I extract the data from the form and place it into the Donation object?
I've noticed that many tutorials overlook my initial question, leaving me wondering if my form is incomplete...