English 中文(简体)
Load ASP。 Net MVC JSONResult jQuery DataTables
原标题:Load ASP.Net MVC JSONResult jQuery DataTables

I m试图获得数据表(http://datatables.net),以便与一个协会返回的JsonResult合作。 Net MVC 主计长。 我不断收到“可发射警报(表id=实例): 要求从数据来源获得的用于0级“差错”的不为人知的参数0,根据该数字,这意味着它无法找到栏目。

The code in controller that returns the JsonResult looks like:

    public JsonResult LoadPhoneNumbers()
    {
        List<PhoneNumber> phoneNumbers = new List<PhoneNumber>();
        PhoneNumber num1 = new PhoneNumber { Number = "555 123 4567", Description = "George" };
        PhoneNumber num2 = new PhoneNumber { Number = "555 765 4321", Description = "Kevin" };
        PhoneNumber num3 = new PhoneNumber { Number = "555 555 4781", Description = "Sam" };

        phoneNumbers.Add(num1);
        phoneNumbers.Add(num2);
        phoneNumbers.Add(num3);

        return Json(phoneNumbers, JsonRequestBehavior.AllowGet);
    }

电话: C 具有2种特性、编号和说明的组类。

检索和装载数据的java字母如下:

<script>
$(document).ready(function () {
    $( #example ).dataTable({
        "bProcessing": true,
        "sAjaxSource":  /Account/LoadPhoneNumbers/ ,
        "sAjaxDataProp": ""
    });
});
</script>

而html则认为:

<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
    <tr>
        <th>
            Number
        </th>
        <th>
            Description
        </th>
    </tr>
</thead>
<tbody>
</tbody>
<tfoot>
</tfoot>
</table>

我故意将SAjaxDataprop定在空洞中,以便数据可点不上aData。 即便在我向控制人员明确提出类似要求时:

return Json(new { aaData = phoneNumbers });

我仍然有错误。 任何建议都请?

感谢!

最佳回答

对我来说,以下工作是巨大的:

$(function () {
    $( #example ).dataTable({
        bProcessing: true,
        sAjaxSource:  @Url.Action("LoadPhoneNumbers", "Home") 
    });
});

我删除了<条码>sAjaxDataProp。

(a) 收集数据来源:

public ActionResult LoadPhoneNumbers()
{
    return Json(new
    {
        aaData = new[] 
        {
            new [] { "Trident", "Internet Explorer 4.0", "Win 95+", "4", "X" },
            new [] { "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", "1.8", "A" },
            new [] { "Webkit", "iPod Touch / iPhone", "iPod", "420.1", "A" }
        }
    }, JsonRequestBehavior.AllowGet);
}

仅凭电话:

public ActionResult LoadPhoneNumbers()
{
    var phoneNumbers = new List<PhoneNumber>(new[] 
    {
        new PhoneNumber { Number = "555 123 4567", Description = "George" },
        new PhoneNumber { Number = "555 765 4321", Description = "Kevin" },
        new PhoneNumber { Number = "555 555 4781", Description = "Sam" }
    });

    return Json(new
    {
        aaData = phoneNumbers.Select(x => new[] { x.Number, x.Description })
    }, JsonRequestBehavior.AllowGet);
}
问题回答




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签