无法在 Kentico 12 中创建新的 MVC 小部件

Unable to Create New MVC Widget in Kentico 12

我正在尝试创建一个名为“图像摘要部分”的新小部件。我正处于起步阶段,我只是想在将小部件添加到页面时让小部件出现在小部件列表中。相反,我只是得到了我没有创建的现有小部件:

您可以看到我已经创建了一个实现 IWidgetProperties 的 class 并且我已经为它调用了 RegisterWidget。我还创建了 _ImageSummarySection.cshtml(不过,我不希望仅仅为了让小部件出现在小部件 selection 对话框中就需要这样做)。

上面的解决方案是针对 MVC 网站的,下面的解决方案是针对 Kentico CMS 的。两者都是 运行,显示的浏览器是 Kentico CMS(我试图在此屏幕截图中添加我的新小部件,但它不在小部件列表中)。

知道我做错了什么吗? 如何让我的小部件出现在小部件列表中?

附加信息:

.

.

.

.

.

.

编辑:

我刚刚看了这个视频,希望它能提供见解:https://www.youtube.com/watch?v=ljQO9on5lLM

它比我预期的更基本,但我确实注意到了这两个框架:

请注意,它显示了 select 来自的六个可用小部件。

然后是这个框架:

它只显示了两个可用的小部件。

据此,我推断部分可能具有一些功能,允许开发人员限制其中允许使用哪些小部件。 我是否需要做些什么才能让我的小部件作为选项出现在默认部分(如下所示)?

.

.

.

.

.

.

编辑#2:

我稍微研究了小部件限制并发现了这个:https://docs.kentico.com/k12/developing-websites/page-builder-development/creating-pages-with-editable-areas-in-mvc

特别是标题为“限制可编辑区域中允许的小部件”的部分,内容如下:

由于我的观点没有传递带有小部件白名单的参数,因此应该(理论上)允许所有小部件:

@* Index.cshtml *@
@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Web.Mvc

<h1>Rhythm Agency</h1>

@Html.Kentico().EditableArea("main")

所以有那个理论。我仍然不知道为什么我的新小部件在向页面添加新小部件时没有作为选项出现。

你快到了。您需要创建另一个 class 并在 App_Start 文件夹中注册您的小部件。也请查看 documentation here on that. It's the section on widget registration. Be sure to enable Page builder

*** 已更新 ***

根据您的更新以及无法在我的移动设备上清楚地看到图像,我能够在您的属性模型中看到您是 defining/registering 您的小部件。这需要在控制器中完成。请参阅下面的示例。

\Models\Widgets\JobListingWidgetProperties.cs

namespace NameSpace.Models.Widgets.JobListingWidget
{
    public class JobListingWidgetProperties : IWidgetProperties
    {
        // property definitions here
    }
}

\Models\Widgets\JobListingModelView.cs

namespace NameSpace.Models.Widgets.JobListingWidget
{
    public class JobListingWidgetViewModel
    {
        // properties here
    }
}

\Controllers\Widgets\JobListingWidgetController.cs

[assembly: RegisterWidget("NameSpace.Widgets.JobListingWidget", typeof(JobListingWidgetController), "职位列表小部件", Description = "显示给定路径的职位列表", IconClass = "icon-heartshake" )]

namespace NameSpace.Controllers.Widgets
{
    public class JobListingWidgetController : WidgetController<JobListingWidgetProperties>
    {
        public ActionResult Index()
        {
            // code here
        }
    }
}

要识别控制器和小部件,您需要将控制器放在“/Controllers”文件夹中。我的小部件控制器位于“/Controllers/Widgets”文件夹中。

我遇到的问题包括没有在 class 名称中添加后缀 'Controller' 以及小部件控制器不在“/Controllers”文件夹中的问题。

你不是在单独的项目中工作吗?因为这需要您在 'AssemblyInfo.cs'

中使用以下内容
using CMS;
[assembly: AssemblyDiscoverable]

并确保您已在您的 kentico 项目中启用页面构建器功能。例如:

protected void Application_Start()
{
    ...

    // Gets the ApplicationBuilder instance
    // Allows you to enable and configure Kentico MVC features
    ApplicationBuilder builder = ApplicationBuilder.Current;

    // Enables the preview feature
    builder.UsePreview();

    // Enables the page builder feature
    builder.UsePageBuilder();

    ...
}