Json数据视图不工作MVC

时间:2017-11-23 21:27:42

标签: javascript html .net asp.net-mvc asp.net-mvc-4

控制器:在我的控制器中,我从sap b1if服务获取数据。 我想从控制器获取json数据以查看。

[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格式的Controller获取并使用Bootstrap以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 />

1 个答案:

答案 0 :(得分:0)

将问题放在此处是否是拼写错误,或者您忘记在javascript中正确关闭tr和td标记。