I'm trying to redirect to a controller action and pass the ID of the selected tree node into the controller action.
Ideally, I would like to use some code like this:
<div class="kendo-tree"> @(Html.Kendo().TreeView() .Name("treeview") .DataTextField("Name") .TemplateId("treeview-template") .DataSource(dataSource => dataSource .Read(read => read.Action("DashboardTree", "Home")) ) .Events(e => e.Select("onSelect")) )</div>function onSelect(e) { var data = $('#treeview').data('kendoTreeView').dataItem(e.node); //alert("node clicked" + data.id); window.location = @Url.Action("Edit", "Employee", new { id = data.id }); }Thanks,
bh
5 Answers, 1 is accepted
You are mixing server-side URL helpers with client-side event arguments, which is impossible. data.id is a client-side object and is undefined server-side at the time Url.Action is created. Please use a plain string URL instead of Url.Action().
Dimo
Telerik
It's been a while and I ended up bailing on the TreeView. I used a ListView with templates. The templates are used to build the URL. Here's some code:
Template code:
<script type="text/x-kendo-tmpl" id="template">
<div class="DashboardEmployee">
<div><img src="#: ThumbnailURL #" alt="#:LastName# image" /></div>
<div class="DivText"><a href="@Url.Action("Edit", "Employee")/#:Id#">#:LastNameFirst#</a> <br />#:DepartmentName #</div>
</div>
</script>
Here's the ListView:
<div style="width: 200px; overflow:hidden;">
@(Html.Kendo().ListView<Shiner.ViewModels.EmployeeIndexVM>()
.Name("employeeList")
.TagName("div")
.ClientTemplateId("template")
.Events(events => events
.Change("listviewClicked")
)
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("Employees_Json", "Home"));
dataSource.PageSize(7);
})
.Pageable(p => p.Numeric(false))
.Selectable()
)
</div>
public ActionResult Employees_Json([DataSourceRequest] DataSourceRequest request)
{
var emps = GetEmployees();
var jsonResult = Json(emps.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
return jsonResult;
}
This works pretty well. You could probably use the same technique with the TreeView though I have not tried it. Hope this helps!
Bill
I'm about to dump the treeview as well because of the vague documentation. I'm stuck with trying to create action links for the nodes. Basically when you click a node, an action on the controller is called. I see where they do it for a grid but of course, and maybe I just can't find it but I get frustrated with their docs and how they expect everyone to do everything in jquery (not razor). Instead of a treeview I was going to use bootsrap buttons/links. Not sure what to do...giving me a headache.
The following forum thread discusses the same topic in detail:
http://www.telerik.com/forums/treeview-20cb0e6f0667
Regards,
Dimo
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.
