Something like below should help:
Client Code:
$("#Customer").change(function () {
var name = $("[id*='Customer'] :selected").text();
$.ajax({
url: '/Sale/getCustomerId',
datatype: "json",
type: "POST",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ CusName: name }),
async: true,
processData: false,
cache: false,
success: function (Data) {
cusid= Data;
},
error : function (xhr) {
return null;
},
error: function (exception) {
swal("Ooops", 'Exeption:' + exception, "error");
}
})
})
Server code:
public JsonResult getCustomerId(string CusName)
{
return Json (result);
}
Similar question, refer:
Ajax call in ASP MVC not working[
^]