Иногда мне нравится использовать реализации HTML5/Javascript в системе Kendo, потому что вы можете немного облегчить некоторые вещи. В этом случае мне нужно знать количество результатов, чтобы я мог отображать сетку кендо или нет, однако в других случаях мне нужно изменить источник данных на основе ввода пользователя на стороне клиента. К сожалению, вы не можете получить число результатов или изменить источник данных (насколько мне известно) с использованием оберток MVC. Как я могу вызвать контроллер с помощью Javascript-реализации источника данных Kendo?Javascript Kendo Datasource, вызывающий MVC-контроллер
1
A
ответ
4
Я был в состоянии получить эту работу, используя следующий код:
Контроллер:
public ActionResult GetStuff(string parameter)
{
// Get your data here ...
var data = GetData(parameter);
return Json(data, JsonRequestBehavior.AllowGet);
} // end
Markup/cshtml:
<div id='myGrid'></div>
<script>
$(document).ready(function() {
// Define the dataSource, note that the schema elements are specified
var dataSource = new kendo.data.DataSource({
dataType: "json",
type: "GET",
transport: {
read: '@Url.Action("MethodName", "ControllerName", new {parameter = myParameter})'
},
schema: {
data: "Stuff",
total: "TotalNumberofStuff",
errors: "ErrorMessage"
}
});
}
// Call fetch on the dataSource - this gets the data - the fetch method will make only one call.
// Please note that the datasource fetch call is async, so we must use it's results within the fetch function.
dataSource.fetch(function() {
var numberOfItems = dataSource.total();
if (numberOfItems == 0) {
// If 0 items are returned show the label that says there are no items
$("#myGrid").append("<p><label style='font-size: small; color: red;'>-- No Items --</label></p>");
}
else {
$("#myGrid").kendoGrid({
dataSource: dataSource,
height: function() {
return (numberOfItems >= 1 && numberOfItems <= 5) ? null : "225";
},
columns: [
{ field: "StuffId", title: "Id", width: 150 },
{ field: "Stuff", title: "Stuff", width: 150 }
]
});
}
});
</script>
Смежные вопросы
- 1. Kendo Listview + Kendo DataSource + Template
- 2. Kendo Datasource ответ пуст
- 3. Что такое Kendo DataSource?
- 4. Kendo UI DropdownList dataSource
- 5. Kendo Grid Фильтрация dataSource
- 6. Kendo dataSource Параметр Карта
- 7. Наполнение Kendo Read datasource
- 8. Kendo ui datasource refresh?
- 9. Обновление Kendo UI Datasource
- 10. Kendo Datasource refresh
- 11. Query Kendo UI DataSource
- 12. kendo datasource pagination
- 13. Параметры фильтра Kendo DataSource
- 14. Kendo - Change DataSource onclick
- 15. Kendo chart datasource
- 16. DateTimeOffset и kendo Datasource
- 17. Kendo DataSource и вложенный Json
- 18. Kendo UI Удаленная модификация DataSource
- 19. Kendo Datasource CRUD с шаблонами
- 20. Kendo DataSource Фильтрация оператора «меньше»
- 21. Kendo DataSource Single-Row Read
- 22. kendo datasource отправка jquery string
- 23. C# Dictionary to Kendo DataSource
- 24. kendo scheduler datasource обязательные поля
- 25. Kendo Datasource новая синхронизация данных
- 26. Фильтр Kendo DataSource по дате
- 27. kendo local и remote datasource
- 28. Откат сетки Kendo, вызывающий удаление строки
- 29. Kendo UI dataSource получает набор с использованием объекта javascript
- 30. kendoui grid datasource читать не вызывающий сервер