2012-09-21 2 views
2

MVC4를 사용하여 웹 응용 프로그램을 개발 중입니다. UI에 HandsOnTable이 있습니다. json을 사용하여 데이터를 바인딩하려고 시도했지만 기울어졌습니다. 쇼 오류를 알려주지 않습니다. 여기에 여기에 코드MVC에서 핸즈프리 테이블을 바인딩하는 방법

$.ajax({ 
      url: "/Customer/GetSpreadSheetGrid", 
      type: "GET", 
      dataType: "json", 
      data: { customerId: customerID } 
     }) 
      .success(function (result) { 
    var vSpreadSheet = document.getElementById("SpreadSheetgrid"); 
     $("#SpreadSheetgrid").handsontable("loadData", result); 
    }) 
    .fail(function (r, o) { 
     alert("Failed : " + r.responseText); 
    }); 
    } 

이고 것은 내 컨트롤러 방법

public JsonResult GetSpreadSheetGrid(int customerId) 
    { 
IEnumerable<tblCustomerSpreadsheetInfo> resResult = null; 
// Calling SP 
resResult = _customer.GetCustomerCustomInfoByCustomerID(customerId); 
return Json(resResult, JsonRequestBehavior.AllowGet); 
    } 

입니다 뭐죠이 코드의 실수.

+0

여기에서 실패하고 있습니다. 아약스 또는 손수건? – amesh

답변

0

모두 성공과 실패 함수 내부 디버거를 유지 (다음과 같이 JQuery와 아약스를 수정합니다. (있는 경우).이 당신이 오류를 볼 수 있습니다 IE 및 Visual Studio 디버그를 사용하여.

$.ajax({ 
     url: "/Customer/GetSpreadSheetGrid", 
     type: "GET", 
     data: { customerId: customerID }, 
     contentType: "application/json; charset=utf-8", 
     success: function (_results) { 
      debugger; 
      var vSpreadSheet = document.getElementById("SpreadSheetgrid"); 
      $("#SpreadSheetgrid").handsontable("loadData", result); 
     }, 
     error: function (_results, status) { 
      debugger; 
     } 
    }); 
+0

멍청한 질문 : ASP.NET MVC를 사용하면 일반적으로 뷰에서 렌더링 된 첫 번째 웹 페이지에서 테이블을 원래 렌더링하는 것입니까? 후속 페이징은 JSON을 반환하지만 웹 개발자에게는 많은 경험이없는 ajax 호출을 사용하여 수행된다는 것을 이해합니다. 어떻게 작동하는지 완전히 그림 할 수는 없습니다. 동적으로 생성 된 자바 스크립트에 json 데이터가 포함 된 첫 번째 페이지를 동적으로 서버에 구축하겠습니까? 나는 생각하지 않는다. 우리가 핸즈프리 테이블로 테이블을 초기화 할 때 첫 번째 데이터 바인딩을 어떻게 얻는 지 궁금합니다. 내 무지 미안해. – ChadD

3
<div id="dataTable" class="dataTable"></div>  
$("#dataTable").handsontable({ 
     rows: 6, 
     cols: 8, 
     contextMenu: true, 
     colHeaders: true 
    }); 
    var url = "/Home/GridData"; 
    $.get(url, null, function (data) { 
    $("#dataTable").handsontable("loadData", data); 
    strong text}); 

이가이다 HomeController

의 방법
public JsonResult GridData() 
     { 
      var jsonData = new[] 
         { 
          new[] {"1", "4", "Is this a good question?"}, 
          new[] {"2", "5", "Yes."}, 
          new[] {"3", "6", "It is!"} 
         }; 

      return Json(jsonData, JsonRequestBehavior.AllowGet); 
     } 

이 코드와 handsontable에 컨트롤러 메소드 바인딩 달성했다. 하지만 난 정말 데이터를 가져 오는 고군분투하고 string [] []으로 컨트롤러 메서드에 전달합니다.