0
MVC 모델 바인딩을 사용하여 2 개의 Select2를 사용합니다.select2 사용 MVC 모델 바인딩 사용
한 모델 목록 값과 첫 번째 조건에서 두 번째 챙기고 값 아약스와
있습니다.
CHTML :
<select asp-for=select2firstdropdown tabindex="19">
@foreach (DataRow item in (ViewData["listone_obj"] as DataTable).Rows)
{
<option value="@item["ListID"]" selected>@item["ListTitle"]</option>
}
</select>
<select asp-for=select2seconddropdown tabindex="19"></select>
및 JS 지금
$(document).ready(function() {
$("#select2firstdropdown").select2();
$("#select2seconddropdown").select2({
language: "fa",
ajax: {
url: "/Contraoller/Getlistforseconddorpdown",
dataType: 'json',
delay: 250,
data: function (params) {
return {
searchterm: params.term, // search term
publicationid: $("#select2firstdropdown").val(),
page: params.page
};
},
processResults: function (data, params) {
params.page = params.page || 1;
var o = JSON.parse(data);
return {
results: $.map(o, function (item) {
return {
text: item.title,
id: item.id
}
}),
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 0
});
$("#select2firstdropdown").val(select2firstdropdownselectedID);
$("#select2seconddropdown").val(select2seconddropdownselectedID).trigger("change");
}
나 모델 결과 뷰를 열면, 제 selec2 드롭 선택된 값을 나타내고 있지만, 두 번째는 비어있다.
당신은'사용 select2'의 버전은 무엇입니까에서 선택하려면 더
option
요소가 없다? –임원 –