我的KendoListView会填充正确数量的项目,但不会正确填充这些字段。数据作为JSON结果从我的控制器传入,我在列表视图中获取正确数量的项目,但模板呈现“Member:undefined undefined”。奇怪的是,这几乎是我从一个类似的视图一对一的复制和粘贴,它工作正常。
ListView代码:
@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
更新:我的Controller方法返回正确数量的数组,但它们是空白的......不知道为什么。这是我的constroller代码:
[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));
}