0

我的 KendoListView 填充了正确数量的项目,但没有正确填充字段。数据作为 JSON 结果从我的控制器传入,我在列表视图中获得了正确数量的项目,但模板呈现“成员:未定义未定义”。奇怪的是,这几乎是从我拥有的类似视图进行的一对一复制和粘贴,并且效果很好。

列表视图代码:

@section head
{
    <script type="text/javascript">
        var dataSource;

        $(document).ready(function () {
            dataSource = new kendo.data.DataSource({
                schema: {
                    data: "Data",
                    total: "Total",
                    model: {
                        fields: {
                            MemberID: { editable: false, nullable: false },
                            FirstName: { editable: false, nullable: false },
                            LastName: { editable: false, nullable: false }
                        }
                    }
                },
                transport: {
                    read: {
                        url: "@Url.Action("GetMembers", "Pages", new { area = "Admin" })",
                        contentType: "application/json",
                        type: "POST"
                    }
                }
            });

            $("#memberList").kendoListView({
                autoBind: false,
                dataBound: function (e) {
                    if (dataSource.total() == 0) {
                        $("#MemberList").html('<tr><td>There are no members at this time.</td></tr>');
                    };
                },
                dataSource: dataSource,
                template: kendo.template($("#memberTemplate").html())
            });

            dataSource.read();
        });
    </script>
}

<script type="text/x-kendo-template" id="memberTemplate">
<tr>
    <td style="padding-right:10px;padding-left:10px">
        Member: #= FirstName # #= LastName #
    </td>
</tr>
</script>

<div>
    <table>
        <tbody id="memberList"></tbody>
    </table>
</div>

传入的模型模式:

string Address1
string Address2
string Address3
bool BeLeader
string City
string EmailAddress
string FirstName
string LastName
Guid MemberID
string PhoneNumber
bool ReceiveEmails
Guid StateID
string Zip

更新:我的控制器方法返回正确数量的数组,但它们是空白的......不知道为什么。这是我的控制器代码:

[Authorize]
    [HttpPost]
    public JsonResult GetMembers([DataSourceRequest]DataSourceRequest request)
{
    List<Member> results = new List<Member>();

    try
    {
        results = adminServices.GetMembers();
    }
    catch
    {
    }

    JsonResult test = Json(results.ToDataSourceResult(request));
    return Json(results.ToDataSourceResult(request));
}
4

0 回答 0