2016-09-28 2 views
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 드롭 선택된 값을 나타내고 있지만, 두 번째는 비어있다.

+0

당신은'사용 select2'의 버전은 무엇입니까에서 선택하려면 더 option 요소가 없다? –

+0

임원 –

답변

0

당신은 어떤 옵션을 사용하여 두 번째 드롭 다운을 초기화되지 않으므로 값

+0

에서 최신 버전 "Select2 4.0.2"를 사용 중입니다. 답변을 주셔서 감사합니다. –