2013-03-05 3 views
2

Select2 jquery 플러그인 (MVC3, 면도기 및 녹아웃 JS) 및 AJAX 호출에 전달하려는 사용자 정의 매개 변수에 문제가 있습니다.select2 jquery 플러그인의 데이터 섹션에 배열 전달

$('#QuickSearchPresentation').select2({ 
     placeholder: "Search for a movie", 
     minimumInputLength: 1, 
     ajax: { // instead of writing the function to execute the request we use Select2's convenient helper 
      url: '@Url.Action("QuickSearchMainContainerFromPresentationByIdFolders", "DataCenter", new { amount = 10 })', 
      contentType: 'application/json', 
      dataType: 'json', 
      type: 'POST', 
      quietMillis: 400, 
      data: function (term, page) { 
       return ko.toJSON({ 
        term: term, 
        idFolders: vm.Container.Catalogs 
       }); 
      }, 
      results: function (data, page) { // parse the results into the format expected by Select2. 
       // since we are using custom formatting functions we do not need to alter remote JSON data 
       console.log('results', data); 
       return {results: data}; 
      } 
     }, 
     initSelection: function(element, callback) { 

      console.log('element', element); 

     }, 
     formatResult: containerQuickSearchResult, // omitted for brevity, see the source of this page 
     formatSelection: containerQuickSearchResult, // omitted for brevity, see the source of this page 
     dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller 
     escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results 
    }); 

VM이 녹아웃 JS에서 내 모델이며, INT 년대의 그것의 배열을 카탈로그 :

나는이 코드를 가지고있다.

문제는 내 서버의 Action에 idFolders 배열을 전달할 수 없다는 것입니다. 서버는 null 값일 수 없습니다. 매개 변수 이름 :. 소스 "(배열 내 컨트롤러의 동작에 널 얻을 수 있기 때문에) 나는 내가 생각 가능한 모든 방법을 시도하고 내가 올바른 방법을 찾을 수 없습니다

나는 당신이 좀 도와 수 있기를 바랍니다

.. ..

감사합니다, 곤잘로 당신의 jQuery Ajax 호출에

답변

0

, 데이터 속성에 대해이 같이 JSON.stringify()에 포장하려고 :

data: function (term, page) { 
    return JSON.stringify(ko.toJSON({ 
     term: term, 
     idFolders: vm.Container.Catalogs 
    })); 
}, 

내가 발견 한 그 JSON 데이터를 포장 .stringify는 MVC를 h로 만듭니다. JSON을 올바르게 작성하십시오.