Every Notch is linked to a selected salarygrade.when you choose a salary grade,the notch must be filtered to that linked salary grade.I am using ajax to do it but it isn't working please help.
What I have tried:
<div class="form-group">
@Html.LabelFor(model => model.SalaryGradeId, htmlAttributes: new )
<div class="col-md-6">
@Html.DropDownListFor(model => model.SalaryGradeId, (List<SelectListItem>)Model.SalaryGradeList, new )
@Html.ValidationMessageFor(model => model.SalaryGradeId, "", new )
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NotchId, htmlAttributes: new )
<div class="col-md-6">
<select class="form-control" id="SalaryNotch_Cbx" onchange="GetAmount();">
</select>
@Html.ValidationMessageFor(model => model.NotchId, "", new )
</div>
</div>
this is the javascript i'm using to pull the information from the api
<script>
function GetAmount() {
$.ajax({
url: baseUrl + 'api/SalaryNotch/' + $("#SalaryNotch_Cbx").val(),
type: 'GET',
headers: { 'Access-Control-Allow-Origin': '*' },
dataType: 'json',
success: function (data) {
if (data.HasError == 0) {
console.log(data.Model);
$("#BasicSalary_Txt").val(data.Model.Monthly)
}
},
error: function (request, error) {
console.log(error);
}
});
}
function GetSalaryNotchByGrades() {
$.ajax({
url: baseUrl + 'api/SalaryGradeByNotch/' + $("#SalaryGrade_Cbx").val(),
type: 'GET',
headers: { 'Access-Control-Allow-Origin': '*' },
dataType: 'json',
success: function (data) {
if (data.HasError == 0) {
console.log(data.Model);
$("#SalaryNotch_Cbx").val(data.Model);
$("#SalaryNotch_Cbx").html("");
$("#SalaryNotch_Cbx").append
$.each($.parseJSON(data), function (i, notch)
{ $("#SalaryNotch_Cbx").append($('<option></option>').val(notch.Id).html(notch.Name)) })
}
},
error: function (request, error) {
console.log(error);
}
});
}
</script>