2017-11-23 4 views
-1

コントローラ:私のコントローラでは、sap b1ifサービスからデータを取得しています。 コントローラーから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

[私は下降したため](http://idownvotedbecau.se/itsnotworking/) –

+0

2つのjqueryには?異なるバージョン? [この質問](https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page) – James

+0

を参照してください。 –

答えて

0

ここに質問を入れながら、それは誤植ですか、あなたは正しくJavaScriptでTRとTDタグを閉じるのを忘れています。

+0

実際に私のAjaxリクエストで同じビューからデータを取得していました –

+0

私のコントローラで見ることができます。私はちょうど部分的なビューを作成し、それに私のajaxコードを追加しました。それは動作します。 –

+0

もtdタグを閉じます。 –

関連する問題