【问题标题】:Trouble disaplying custom section in Umbraco 7.6在 Umbraco 7.6 中无法显示自定义部分
【发布时间】:2019-11-20 11:11:51
【问题描述】:

我正在尝试在 Umbraco 7.6 中构建一个新部分。

我有这种使用从 BaseTree 扩展的树控制器的“旧”方式工作,但它非常难看。

我现在正在尝试使用 TreeController 来实现。我按照以下教程进行操作:

  1. 凯文·吉泽夫斯基 (https://github.com/kgiszewski/LearnUmbraco7/blob/master/Chapter%2016%20-%20Custom%20Sections%2C%20Trees%20and%20Actions/01%20-%20Create%20a%20Section.md)

  2. 另一个来自 Tim Geyssens (https://github.com/TimGeyssens/UmbracoAngularBackofficePages)

但我得到的只是一个没有树的空部分,只有标题:

控制器甚至没有在调试时命中,没有控制台错误,没有 500 错误,也都可以正常编译。

这是我的代码:

trees.config:

<add initialize="true" sortOrder="0" alias="UmbracoBookshelfTree" application="UmbracoBookshelf" title="Umbraco Bookshelf" iconClosed="icon-folder"
    iconOpen="icon-folder-open" type="UmbracoBookshelf.Controllers.UmbracoBookshelfTreeController, MyWebsite.Backoffice"/>

applications.config:

<add alias="UmbracoBookshelf" name="Umbraco Bookshelf" icon="icon-globe-inverted-america" sortOrder="5"/>

部分:

using umbraco.businesslogic;
using umbraco.interfaces;

namespace UmbracoBookshelf.Applications
{
    [Application("UmbracoBookshelf", "Umbraco Bookshelf", "icon-globe-inverted-america", 5)]
    public class UmbracoBookshelfApplication : IApplication
    {
    }
}

树控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web;
using umbraco;
using umbraco.BusinessLogic.Actions;
using Umbraco.Core;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;

namespace UmbracoBookshelf.Controllers
{
    [PluginController("UmbracoBookshelf")]
    [Umbraco.Web.Trees.Tree("UmbracoBookshelf", "UmbracoBookshelfTree", "Umbraco Bookshelf", iconClosed: "icon-folder")]
    public class UmbracoBookshelfTreeController : TreeController
    {

        protected override Umbraco.Web.Models.Trees.MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
        {
            var menu = new MenuItemCollection();

            if (id == Constants.System.Root.ToInvariantString())
            {
                // root actions              
                menu.Items.Add<CreateChildEntity, ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
                menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
                return menu;
            }
            else
            {
                //menu.DefaultMenuAlias = ActionDelete.Instance.Alias;
                menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));

            }
            return menu;
        }

        protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();

            nodes.Add(CreateTreeNode("123", "456", queryStrings, "Some name to be shown"));
            nodes.Add(CreateTreeNode("789", "456", queryStrings, "Some other name to be shown"));

            return nodes;
        }
    }
}

很简单,这里有什么问题?

【问题讨论】:

    标签: umbraco7 custom-sections


    【解决方案1】:

    我看到我的示例和您的示例之间的区别是trees.config 中的, MyWebsite.Backoffice,我建议删除它

    <add initialize="true" sortOrder="0" alias="UmbracoBookshelfTree" application="UmbracoBookshelf" title="Umbraco Bookshelf" iconClosed="icon-folder"
        iconOpen="icon-folder-open" type="UmbracoBookshelf.Controllers.UmbracoBookshelfTreeController"/>
    

    我通过 VS Code 和 IIS Express 运行它。

    提示:我发现使用我上面提到的代码会自动将 App_Code 添加到 config 键中,并变成如下所示:

    <add initialize="true" sortOrder="0" alias="UmbracoBookshelfTree" application="UmbracoBookshelf" title="Umbraco Bookshelf" iconClosed="icon-folder"
        iconOpen="icon-folder-open" type="UmbracoBookshelf.Controllers.UmbracoBookshelfTreeController, App_Code"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-13
      • 1970-01-01
      相关资源
      最近更新 更多