不能使用ajax,jquery根据特定的id获取json数据

时间:2016-10-28 12:27:06

标签: jquery json ajax asp.net-web-api asp.net-ajax

我有一个索引页面,它从我的ASP.NET webapi接收json数据。我的索引页的代码片段以及jquery代码。

  

Index.cshtml

 <table id="meetings">
            <thead>
            <tr>
                <th>Subject</th>
                <th>Regarding</th>
                <th>Full Name</th>
                <th>Mobile</th>
                <th>Email</th>
                <th>Delete</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>




<script>

    $(document).ready(function() {
        var table = $("#meetings").DataTable({
            ajax: {
                url: "/api/meetingrequest/",
                dataSrc: ""
            },
            columns: [
                {
                    data: "subject",
                    render: function (data, type, meeting) {
                     return "<a href='/home/details/" + meeting.id + " '>" + data + "</a>";

                    }

                },
                {
                    data: "requestAMeetingFor.name"
                },
                {
                    data: "fullName"
                },
                {
                    data: "mobileNumber"
                },
                {
                    data: "emailAddress"
                },

                }
            ]
        });
    });

</script>

通过基于id生成超链接并获取(并显示)json数据,这非常有效:     <a href="/home/details/6 ">Driving</a>

我使用&#34; Postman&#34;验证了json数据。我有它。但是,我唯一的问题是我无法在另一个视图上显示基于该特定ID的数据,比方说,当单击链接时,它应该采用新视图,例如,详细信息并显示与该视图相关的数据particalr ID.I可以通过Postman中的ID查看这些数据。

Json data by Postman -screenshot

  

Details.cshtml

 <table id="meetings" class="table table-bordered table-hover table-responsive">
        <thead>
            <tr>
                <th>Subject</th>
                <th>Regarding</th>
                <th>Full Name</th>
                <th>Mobile</th>
                <th>Email</th>
                <th>Message</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>


</div>

<script>

    $(document).ready(function () {
        var table = $("#meetings").DataTable({

            ajax: {
                type:"GET",
                url: "/api/meetingrequest/" +id,
                dataType: 'JSON',
                dataSrc: ""
            },
            columns: [
                {
                    data: "subject"


                },
                {
                    data: "requestAMeetingFor.name"
                },
                {
                    data: "fullName"
                },
                {
                    data: "mobileNumber"
                },
                {
                    data: "emailAddress"
                },
                {
                    data: "message"

                }
            ]
        });
    });
</script>

我们将非常感谢您的帮助。 附:我使用Datatable作为索引页面,但不会用于此解决方案。

0 个答案:

没有答案