After Adding values to my profile packages and inspecting it from my JS that it has data contained in it, but on my server side when i push, ProfilePackages results to count = 0; even when Object List has Data.
This is my JS Code
var formData = new FormData();
formData.append("Title", $("#profileTitle").val());
formData.append("Duration", $("#txtDuration").val());
formData.append("StartingPrice", $("#startPrice").val());
formData.append("Description", $("#txtDescription").val());
formData.append("CategoryId", $("#SubCatDropDown").val());
$("#tablePackage tbody tr").each(function () {
var packageDetails = {};
packageDetails.Description = $(this).find("#desc").val();
packageDetails.Amount = $(this).find("#amount").val();
packageDetails.Duration = $(this).find("#hours").val();
formData.append("ProfilePackages", JSON.stringify(packageDetails));
});
$.each($("#skills option:selected"), function (i, selected) {
formData.append('ProfileSelectedSkills', selected.value);
console.log(selected.value);
});
$.each($('.fileUpload')[0].files, function (key, input) {
formData.append('Files', input);
console.log(input);
});
$.ajax({
async: true,
type: 'POST',
dataType: 'JSON',
contentType: 'application/json; charset=utf-8',
data: formData,
processData: false,
contentType: false,
url: '/F/Profile/FAddProfile?handler=SaveProfile',
beforeSend: function (xhr) {
xhr.setRequestHeader("MY-XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
success: function (data) {
alert(data);
window.location = '/F/Profile/FProfile'; // redirect
},
error: function () {
alert("Something went wrong");
}
});
And this is my Controler Model
public int Id { get; set; }
public string Description { get; set; }
public int CategoryId { get; set; }
public decimal StartingPrice { get; set; }
public int Duration { get; set; }
public string Title { get; set; }
public virtual List<ProfileSkill> ProfileSkills { get; set; } = new List<ProfileSkill>();
public virtual List<ProfileFiles> ProfileFiles { get; set; } = new List<ProfileFiles>();
public virtual List<ProfilePackage> ProfilePackages { get; set; } = new List<ProfilePackage>();
When i push, ProfilePackges result to count = 0