This question is locked. New answers and comments are not allowed.
We are coding an MVC TreeView and need to be able to format the child nodes adding specific attributes.
We have added our custom attributes in the root node using HtmlAttributes.Add, ("NodeType" is being added to the root node in this example), but we are unable to attach the attributes to the child nodes.
Any help would be appreciated. Thanks.
Index.aspx
SendProfileController.cs
We have added our custom attributes in the root node using HtmlAttributes.Add, ("NodeType" is being added to the root node in this example), but we are unable to attach the attributes to the child nodes.
Any help would be appreciated. Thanks.
Index.aspx
<%=Html.Telerik().TreeView() .Name("TreeViewUser") .ShowCheckBox(true) .ClientEvents(events => events .OnChecked("OnClientNodeChecked") ) .BindTo(UserTreeViewModel.GetDefaultTreeNodes(), (item, user) => { item.Text = user.Name; item.Value = user.ID.ToString(); item.HtmlAttributes.Add("NodeType", user.Type); item.LoadOnDemand = true; }) .DataBinding(dataBinding => dataBinding .Ajax().Select("LoadNodesMVC", "SendProfile") ) %> SendProfileController.cs
[JsonParamFilter(Param = "node", TargetType = typeof(TreeViewItem))] public virtual JsonResult LoadNodesMVC(TreeViewItem node) { List<UserTreeViewModel> users = GetUsersFromSession(); var nodes = from user in users where user.ParentID.ToString() == node.Value select new TreeViewItem() { Text = user.Name, Value = user.ID.ToString(), Expanded = false }; return Json(new { d = nodes.ToArray() }); }