I'm new to Ajax, and I'm trying to turn off the checkbox if certain items are selected from the drop-down list. I need to pass the GetMlaDeliveryType (int Id) method to RecipientsController.cs in mlaId.
I'm not quite sure how to set up ajax call in javascript function checkMlaDeliveryType (mlaId).
// MLA Add disable express checkbox if delivery type is electronic $('.AddSelectedMla').change(function () { var deliveryType = checkMlaDeliveryType($('.AddSelectedMla').val()); // disable express option if delivery type is Electronic if (deliveryType == "Mail") { $(".mlaExpressIndicator").removeAttr("disabled"); }else{ $(".mlaExpressIndicator").attr('checked', false).attr("disabled", true); } }) // ajax call to get delivery type - "Mail" or "Electronic" function checkMlaDeliveryType(mlaId) { $.ajax({ type: "GET", url: "/Recipients/GetMlaDeliveryType/" , data: mlaId, dataType: , success: }); } RecipientsController.cs public string GetMlaDeliveryType(int Id) { var recipientOrchestrator = new RecipientsOrchestrator(); // Returns string "Electronic" or "Mail" return recipientOrchestrator.GetMlaDeliveryTypeById(Id); }
EDIT:
This is what the latest javascript looked like that worked
// MLA Add disable express checkbox if delivery type is electronic $('.AddSelectedMla').change(function () { checkMlaDeliveryType($('.AddSelectedMla').val()); }) // ajax call to get delivery type - "Mail" or "Electronic" function checkMlaDeliveryType(mlaId) { $.ajax({ type: 'GET', url: '@Url.Action("GetMlaDeliveryType", "Recipients")', data: { id: mlaId }, cache: false, success: function (result) { // disable express option if delivery type is Electronic if (result == "Mail") { $(".mlaExpressIndicator").removeAttr("disabled"); } else { $(".mlaExpressIndicator").attr('checked', false).attr("disabled", true); } } }); }
source share