【问题标题】:Telerik MVC Panel Bar getting reloaded for each Panel Bar Item actionTelerik MVC 面板栏为每个面板栏项目操作重新加载
【发布时间】:2019-03-06 14:33:02
【问题描述】:
我正在使用 Telerik MVC 面板栏作为我的应用程序的侧边菜单栏。我指的是这个链接Demo
我确实将我的模型绑定(本地数据绑定)到面板栏,它工作正常。我的问题是如何使面板栏 Item.Action("Action","Controller") 成为 AJAX 调用。因为每次我点击菜单时,我的页面都会重新加载。
我无法在 Telerik MVC 部分找到任何解决方案。
任何帮助将不胜感激。
【问题讨论】:
标签:
kendo-ui
telerik
telerik-mvc
kendo-panelbar
【解决方案1】:
您可以定义数据源的 URL。
此示例来自 Telerik 文档。
查看
@(Html.Kendo().PanelBar()
.Name("panelbar")
.DataTextField("Name")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetEmployeesJson", "Controller")
)
)
)
控制器中的操作
public JsonResult GetEmployeesJson(int? id)
{
var dataContext = new SampleEntities();
var employees = from e in dataContext.Employees
where (id.HasValue ? e.ReportsTo == id : e.ReportsTo == null)
select new
{
id = e.EmployeeID,
Name = e.FirstName + " " + e.LastName,
hasChildren = e.Employees1.Any()
};
return Json(employees, JsonRequestBehavior.AllowGet);
}