Jquery数据表 - 无法绑定数据 - ASP.NET MVC,jquery [英] Jquery datatables - can't bind data - ASP.NET MVC, jquery
问题描述
大家好,
我的应用程序(ASP.NET MCV)引用Web服务来获取GET数据&使用DataTables jQuery(https://datatables.net/)显示。
我尝试过:
创建ajax函数来调用Controller / Action。
Hi all,
My application (ASP.NET MCV) refrences a Webservice to GET data & display using DataTables jQuery (https://datatables.net/).
What I have tried:
Created ajax function to call Controller/ Action.
<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/DataTables/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: 'POST',
url: '@Url.Action("GetDetailsFromService", "GetProductData")',
dataType: "json",
success: function (DBdata) {
alert(DBdata); //Data To Display in Alertbox
$('#productDataTable').DataTable({
data: DBdata,
columns: [
{ "data": "ProductName" },
{ "data": "SupplerName" },
{ "data": "CategoryName" }]
});
}
});
});
</script>
消费的Web服务数据显示。
Consumed Webservice data to show.
[HttpPost]
public ActionResult GetDetailsFromService()
{
ProductDetails.GetDetailsService service = new ProductDetails.GetDetailsService();
JavaScriptSerializer json = new JavaScriptSerializer();
return Json(json.Serialize(service.GetProductData()), JsonRequestBehavior.AllowGet);
}
来自webservice的警告框中显示的JSON数据。
无法将数据绑定到jQuery DataTable。
请帮帮我,弄明白。
JSON data shown in alert box from webservice.
Can't bind data to jQuery DataTable.
Please help me, to figure out.
推荐答案
( document ).ready( function (){
(document).ready(function () {
.ajax({
type:' POST',
url:' < span class =code-string> @ Url.Action(GetDetailsFromService,GetProductData)',
dataType: < span class =code-string> json,
success: function (DBdata){
alert(DBdata); // 要在Alertbox中显示的数据
.ajax({ type: 'POST', url: '@Url.Action("GetDetailsFromService", "GetProductData")', dataType: "json", success: function (DBdata) { alert(DBdata); //Data To Display in Alertbox
( #productDataTable')。DataTable({
data:DBdata,
columns:[
{ data: ProductName},
{ data: SupplerName},
{ data: CategoryName} ]
});
}
});
});
< / script>
('#productDataTable').DataTable({ data: DBdata, columns: [ { "data": "ProductName" }, { "data": "SupplerName" }, { "data": "CategoryName" }] }); } }); }); </script>
消费的Web服务数据显示。
Consumed Webservice data to show.
[HttpPost]
public ActionResult GetDetailsFromService()
{
ProductDetails.GetDetailsService service = new ProductDetails.GetDetailsService();
JavaScriptSerializer json = new JavaScriptSerializer();
return Json(json.Serialize(service.GetProductData()), JsonRequestBehavior.AllowGet);
}
来自webservice的警告框中显示的JSON数据。
无法将数据绑定到jQuery DataTable。
请帮帮我,弄明白。
JSON data shown in alert box from webservice.
Can't bind data to jQuery DataTable.
Please help me, to figure out.
这篇关于Jquery数据表 - 无法绑定数据 - ASP.NET MVC,jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!