I have listed out the various entities present in my model.
public class Provider
{
public int ProviderId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string SSN { get; set; }
public string NPI { get; set; }
public ProviderDetails ProviderDetails { get; set; }
}
public class ProviderDetails
{
public int ProviderDetailsId { get; set; }
public string Certification { get; set; }
public string Specialization { get; set; }
public string TaxonomyCode { get; set; }
public string ContactNumber { get; set; }
public string ContactEmail { get; set; }
public int ProviderId { get; set; }
}
Here is the controller action method that I am using.
[HttpPost]
public ActionResult CreateProvider(Provider provider)
{
try
{
int providerCreationResult = _repository.CreateProvider(provider);
if (providerCreationResult == 1)
TempData["userIntimation"] = "Provider Successfully Registered";
return RedirectToAction("ShowTheListOfProviders");
}
catch (Exception Ex)
{
_logger.Error(Ex.Message);
return View("Error");
}
}
Data is being sent to the controller via AJAX with the following script.
self.createProviderDetails = function () {
$.ajax({
url: "/Provider/CreateProvider/",
type: "POST",
data: fillModel(),
async: false,
success: function (result) {
if (result.url) {
location.href = result.url;
}
}
}).fail(
function (xhr, textStatus, err) {
alert(err);
});
};
The function responsible for filling up the model is given below.
var fillModel = function () {
var providerData =
{
ProviderId: self.providerID(),
FirstName: self.firstName(),
LastName: self.lastName(),
SSN: self.SSN(),
NPI: self.NPI(),
ProviderDetails: {
ProviderDetailsId: 0,
Certification: self.certification(),
Specialization: self.specialization(),
TaxonomyCode: self.taxonomyCode(),
ContactNumber: self.contactNumber(),
ContactEmail: self.contactEmail(),
ProviderId: self.providerID()
}
}
return providerData;
}
While the object data seems fine on the Javascript side, the nested objects appear as null at the controller end.
I would appreciate any guidance on what might be going wrong here. I'm struggling to pinpoint this issue.