When transmitting data from a JavaScript application to an MVC5 controller, I encounter an issue where the Submit controller action is not being invoked upon data submission. The JSON object created by simple mappers looks like this:
function mapContactDto(vm)
{
var contactDto = {};
contactDto.firstName = vm.firstName();
contactDto.lastName = vm.lastName();
contactDto.companyName = vm.companyName();
// more properties...
return contactDto;
}
// Other mapper functions...
To send the data, the following code snippet is used:
// XMLHttpRequest setup and item creation...
var url = '/Knockout/Submit';
$.ajax({
// Ajax request configuration...
});
The controller code in question is as follows:
public JsonResult Submit(string[] Skus, ContactDto Contact)
{
return Json(new { success = true, message = "Some message" });
}
/* Relevant MVC models... */
Here are some questions that I have regarding this scenario:
If I comment out the controller parameters and make it
Submit()
, the function gets called. Can you explain why?It appears that the controller framework is unable to match up the parameters correctly. Any insights on what might be causing this issue?
What steps can I take to enable debugging on the MVC controller for better insight into the problem?