2017-11-23 2 views
-1

컨트롤러 : 내 컨트롤러에서 서비스를 가져 오는 중입니다. 컨트롤러에서 json 데이터를 보려고합니다. 같은보기에 Json 데이터가 작동하지 않습니다 MVC

[HttpGet] 
    [AllowAnonymous] 
    public ActionResult Index() 
    { 
     ServiceReference1.ipostep_vP001sap0003in_WCSX_comsapb1ivplatformruntime_INB_WS_CALL_SYNC_XPT_INB_WS_CALL_SYNC_XPTipo_procClient B1ifSerPro 
       = new ServiceReference1.ipostep_vP001sap0003in_WCSX_comsapb1ivplatformruntime_INB_WS_CALL_SYNC_XPT_INB_WS_CALL_SYNC_XPTipo_procClient(); 
     ServiceReference1.SelectQueryType request = new ServiceReference1.SelectQueryType(); 
     request.Query = "Select TOP 1000 r.U_JobNr as U_JobNr,r.Code as Code,r.U_HlSQty as U_HlSQty,r.U_JobTp as U_JobTp,r.U_RDate as U_RDate,r.U_RTime as U_RTime,r.U_ASDate as U_ASDate,r.U_ASTime as U_ASTime,r.U_AEDate as U_AEDate,r.U_Lorry as U_Lorry,r.U_Driver as U_Driver,e.U_ZpCd as U_ZpCd,e.U_City as U_City,e.U_Phone1 as U_Phone1,e.U_SiteTl as U_SiteTl,r.U_ConNum as U_ConNum,r.U_CstWgt as U_CstWgt,r.U_Price as U_Price,r.U_TCTotal as U_TCTotal,r.U_SLicCh as U_SLicCh,r.U_PayMeth as U_PayMeth,r.U_JCost as U_JCost,r.U_RTimeT as U_RTimeT,r.U_SLicNr as U_SLicNr,r.U_VehTyp as U_VehTyp,r.U_IDHRTCD as U_IDHRTCD,r.U_IDHSEQ as U_IDHSEQ,r.U_CustRef as U_CustRef,r.U_Rebate as U_Rebate,r.U_WROrd as U_WROrd,r.U_WRRow as U_WRRow,e.U_Status as U_Status,r.U_RowSta as U_RowSta,r.U_LnkPBI as U_LnkPBI,r.U_AddCost as U_AddCost,r.U_AddCharge as U_AddCharge,r.U_ValDed as U_ValDed,e.U_PCardCd as U_PCardCd,e.U_SCardCd as U_SCardCd,r.U_OrdTot as U_OrdTot,r.U_PCTotal as U_PCTotal FROM[@IDH_JOBSHD] r ,[OCRD] bp ,[@IDH_JOBENTR] e WHERE r.U_JobNr = e.Code AND (r.U_CustCd = bp.CardCode Or (r.U_CustCd = '' AND r.U_ProCd = bp.CardCode)) "; 
     ServiceReference1.SelectQueryResponseType Response = B1ifSerPro.ZSelectQuery(request); 

     Response.SelectQueryResult.ToList(); 
     //ServiceReference1.SelectQueryResponseTypeRow row = (ServiceReference1.SelectQueryResponseTypeRow)Response.SelectQueryResult.GetValue(1); 

     return Json(Response.SelectQueryResult.ToList(), JsonRequestBehavior.AllowGet); 
     //return Json("",JsonRequestBehavior.AllowGet); 
    } 

내보기는 다음과 같습니다 JS 내 경우에는 작동하지 않습니다. json 형식 컨트롤러로 데이터를 가져오고 부트 스트랩을 사용하여 HTML로 렌더링하거나 간단하게 작업 할 수 있습니다.

@Model IEnumerable<BusinessLayer.OSM> 

<script src="~/Scripts/jquery-1.10.2.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      var osmlist; 
      $.ajax({ 
       url:'@Url.Action("Index", "OSM")' , // '/OSM/Index/', 
       type: 'Get', 
       Data:{}, 
       cache: false, 
       async: false, 
       DataType: 'Json', 
       success: function (data) { 
        osmlist = data; 
        var row = ''; 
        $.each(data, function (i, item) { 
         row += "<tr>" 
         row += "<td>" + item.Code + "<td>" 
         row += "<td>" + item.U_JobNr + "<td>" 
         row += "<tr>" 
         $("#listRows tbody").html(row); 

        }) 
       }, 
       error: function (error) { 
        alert("Error : " + error.responseText); 
       } 
      }); 

     }); 

    </script> 

    <h2>Get OSM Rows</h2> 
    <table id="listRows" style="background-color: lightcoral"> 
     @*<thead> 
      <tr> 
       <th>ID</th> 
       <th>Name</th> 
       <th>Description</th> 
       <th>Category</th> 
       <th>Price</th> 
      </tr> 
     </thead>*@ 
     <tbody></tbody> 
    </table> 
    <hr /> 
+2

[내가 downvoted 때문에] (http://idownvotedbecau.se/itsnotworking/) –

+0

두 jquery가 포함되어 있습니까? 다른 버전? [이 질문] (https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page) – James

+0

하나만 사용해도 작동하지 않습니다.를 참조하십시오. –

답변

0

여기에 질문을 올리는 동안 오타가 잘못되었거나 자바 스크립트에서 tr 및 td 태그를 올바르게 닫는 것을 잊어 버렸습니다.

+0

감사합니다. 사실 내 컨트롤러에서 볼 수있는 것처럼 내 아약스 요청 –

+0

에서 동일한보기의 데이터를 가져 왔습니다. 방금 부분 뷰를 작성하고 아약스 코드를 추가했습니다. 작동합니다. –

+0

또한 td 태그를 닫습니다. –

관련 문제