I am currently trying to figure out KendoUI. I am using version 2012.1.322.
I have a simple array of strings List<string> returned back to the user in a web method through an AJAX call.
["name","phone","address","zip"]
When the ListView binds the list is empty, I only get
<ul id="fileAlist" data-role="listview" class="k-widget k-listview"></ul>.
I’m pretty sure it has to do with my template being wrong. What do I have to set instead of ${Object} to get it to render like:
<ul id="fileAlist" data-role="listview" class="k-widget k-listview">
<li>name</li>
<li>phone</li>
<li>address</li>
<li>zip</li>
</ul>
Here is the current code:
$(document).ready(function () {
$("#fileAlist").kendoListView({
template: "<li>${Object}</li>",
dataSource:
new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("GetColumnNames", new {File="A"})',
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8"
}
}
})
});
});
C# Code (in-case you’re interested)
[HttpGet]
public JsonResult GetColumnNames(string file)
{
if (file == "A")
{
var columns = new List<string>()
{
"name",
"phone",
"address",
"zip"
};
}
return new JsonResult { Data = columns, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
Some other trial and fails
Here are some of the template ideas I tried and the results that came back. Obviously they all didn’t give me the string output I wanted.
- I tried changing the template to be
template: "<li>${}</li>"and when rendered I get<li>undefined</li> - I tried changing the tempalte to be
template: "<li>$.val()</li>"and when rendered I get<li>$.val()</li> - I tried changing the tempalte to be
template: "<li>${}.selector</li>"and when rendered I get<li>undefined.selector</li>
There are several configuration issues in your code. I’ve simplified the code a bit to concentrate on a working example.
Model class:
View markup, you’ll need to play with the list layout to get the desired look:
Note how the template mark up looks like:
Controller that return json:
–EDIT–
Here is a controller that’ll return a json string without a concrete
Contactobject.