开发者

telerik treeview asp.net mvc - link does not work for non root nodes

I am using this code in my view:

开发者_JAVA百科
@(Html.Telerik().TreeView()
.Name("AjaxTreeView")
.BindTo(Model, (item, category) =>
{
    // bind initial data - can be omitted if there is none
    item.Text = category.Name;
    item.Action("Details", "Categories", new { Id = category.Id });
    item.Value = category.Id.ToString();
    item.LoadOnDemand = category.NOChildren > 0;
})
.DataBinding(dataBinding => dataBinding
        .Ajax().Select("_TreeViewAjaxLoading", "Categories")
)
)

It works fine (ajaxified expand and collapse). The action links work fine but only for the root nodes. My current controller that spews out JSON for the ajax load:

[Transaction]
[HttpPost]
public ActionResult _TreeViewAjaxLoading(TreeViewItem node)
{
    int? ParentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

    var nodes = from item in CategoryRepository.GetChildren(ParentId)
        select new TreeViewItem
        {
            Text = item.Name,
            Value = item.Id.ToString(),
            LoadOnDemand = item.NOChildren > 0
        };
    return new JsonResult { Data = nodes };
}

does not set the action link. How can I set the action link here? Thanks.

Christian


This seems to do the trick:

[Transaction]
[HttpPost]
public ActionResult _TreeViewAjaxLoading(TreeViewItem node)
{
    int? ParentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

    UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext);
    var nodes = from item in CategoryRepository.GetChildren(ParentId)
        select new TreeViewItem
        {
            Text = item.Name,
            Value = item.Id.ToString(),
            LoadOnDemand = item.NOChildren > 0,
            Url =  u.Action("Details", "Categories", new { Id = item.Id} )
        };
    return new JsonResult { Data = nodes };
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜