In my code snippet, I have a JavaScript function that is used to populate a Datalist:
function PopulateDropDown(facility) {
$.ajax({
url: '/Rentals/Base/GetContactsForFacility?selectedFacility=' + facility,
data: { facility: facility },
dataType: 'json',
success: function (result) {
response($.map(result, function (item) {
$('#custServiceContactsSelection').append($("<option />").val(item.ContactName).text(item.ContactName));
}));
},
cache: false,
error: function (jqXHR, textStatus, errorThrown) {
if (errorThrown.indexOf("Your session has timed out") != -1) {
location.href = "/Rentals/Base/Timeout";
}
}
});
}
Below is the method inside my controller for handling this request:
public ActionResult GetContactsForFacility(string selectedFacility)
{
var facilityId = new Guid(selectedFacility);
if (Request.IsAjaxRequest())
{
var contacts = SessionService.AllCustomerServiceContactsForFacility(CrmService, facilityId);
return Json(contacts.Select(x => new { label = x.ContactName }), JsonRequestBehavior.AllowGet);
}
return Content(string.Empty);
}
After running the above code, an error occurs in Visual Studio stating:
JavaScript runtime error: 'response' is undefined
I suspect something is missing in the GetDropDownData() function but I am unsure what exactly it could be. Can you provide some guidance on this issue? Thank you!