从选定的下拉列表中填充下拉列表 [英] Populate a dropdown from a selected dropdown value
本文介绍了从选定的下拉列表中填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每个Notch都链接到一个选定的salarygrade。当你选择工资等级时,必须将缺口过滤到该链接的工资等级。我使用ajax来执行它但是它不起作用请帮助。
我尝试过:
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 { @class = "control-label col-md-2" })
<div class="col-md-6">
@Html.DropDownListFor(model => model.SalaryGradeId, (List<SelectListItem>)Model.SalaryGradeList, new { @class = "form-control", onchange = "GetSalaryNotchByGrades();", @id = "SalaryGrade_Cbx" })
@Html.ValidationMessageFor(model => model.SalaryGradeId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NotchId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
<select class="form-control" id="SalaryNotch_Cbx" onchange="GetAmount();">
</select>
@Html.ValidationMessageFor(model => model.NotchId, "", new { @class = "text-danger" })
</div>
</div>
这是我用来从api中提取信息的javascript >
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
// ($('<option></option>').val(null).html("Select Notch"));
$.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>
推荐答案
.ajax({
url:baseUrl +'api / SalaryNotch /'+
.ajax({ url: baseUrl + 'api/SalaryNotch/' +
(#SalaryNotch_Cbx)。val(),
类型:'GET',
header:{'Access-Control-Allow-Origin':'*'},
dataType:'json',
success:function(data){
if(data.HasError = = 0){
console.log(data.Model);
("#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)
}
},
错误:函数(请求,错误){
console.log(错误);
}
});
}
函数GetSalaryNotchByGrades(){
("#BasicSalary_Txt").val(data.Model.Monthly) } }, error: function (request, error) { console.log(error); } }); } function GetSalaryNotchByGrades() {
这篇关于从选定的下拉列表中填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文