循环递归方法

@functions
{
public string getLinks(Link link)
{
    StringBuilder linkBuilder = new StringBuilder();
    linkBuilder.Append("<div class=\"node\"");
    if (link.Parent != null)
    {
        linkBuilder.Append("style=\"display: none\"");
    }
    linkBuilder.Append(">");
    linkBuilder.Append(" <div class=\"item\">");
    linkBuilder.Append("<div class=\"item-info \">");
    linkBuilder.Append("<span class=\"text-success\">[" + link.Type.GetDisplayName() + "]</span>");
    linkBuilder.Append(" " + link.Name + "&nbsp; &nbsp; &nbsp; &nbsp; ");
    linkBuilder.Append("<a href=\"" + Url.Action(nameof(NY.TBWebApp.Controllers.Admin.LinkController.CreateLink), new { ParentId = link.Id, fromUrl = Context.Request.GetRequestUrl() }) + "\"  class=\"btn btn-info btn-sm\">添加下级</a>&nbsp; &nbsp;");
    linkBuilder.Append(" <a href=" + Url.Action(nameof(NY.TBWebApp.Controllers.Admin.LinkController.EditLink), new { Id = link.Id, fromUrl = Context.Request.GetRequestUrl() }) + " class=\"btn btn-info btn-sm\">编辑</a>&nbsp; &nbsp;");
    linkBuilder.Append("<a href=" + Url.Action(nameof(NY.TBWebApp.Controllers.Admin.LinkController.DeleteLink), new { Id = link.Id, fromUrl = Context.Request.GetRequestUrl() }) + " class=\"btn btn-info btn-sm\" onclick=\"return confirm('是否确认删除?'); \">删除</a>");
    linkBuilder.Append(" </div> <div class=\"clearfix\"></div></div>");
    foreach (var childNode in link.Childs.OrderByDescending(m => m.SortNo).ThenBy(m => m.SortNo))
    {
        linkBuilder.Append(getLinks(childNode));
    }
    linkBuilder.Append(" </div>");
    return linkBuilder.ToString();
}
}

 

posted @ 2018-09-18 21:19  net开发人员  阅读(237)  评论(0编辑  收藏  举报