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

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

问题描述:

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

I'm trying to create a new widget called "Image Summary Section". I'm at the very beginning stages and I'm just trying to get the widget to appear in the list of widgets when adding widgets to the page. Instead, I just get existing widgets that I didn't create:

您可以看到我已经创建了一个实现IWidgetProperties的类,并且为此调用了RegisterWidget.我还创建了_ImageSummarySection.cshtml(尽管,我不希望仅仅为了使小部件出现在小部件选择对话框中).

You can see that I've created a class that implements IWidgetProperties and that I've called RegisterWidget for it. I've also created _ImageSummarySection.cshtml (though, I wouldn't expect that to be necessary just for the widget to appear in the widget selection dialog).

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

The top solution is for the MVC website, and the bottom solution is for the Kentico CMS. Both are running, and the browser shown is the Kentico CMS (I'm trying to add my new widget in this screenshot, but it's not in the list of widgets).

任何关于我做错事情的想法吗? 如何使我的窗口小部件显示在窗口小部件列表中?

Any idea of what I'm doing wrong? How can I get my widget to appear in the list of widgets?

其他信息:

  • 我查看了各种链接,但这是我正在浏览的链接:.

    .

    .

    .

    .

    .

    我刚刚观看了此视频,希望能提供深刻的见解: https://www.youtube .com/watch?v = ljQO9on5lLM

    I just watched this video, hoping it would provide insight: https://www.youtube.com/watch?v=ljQO9on5lLM

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

    It was more basic than I anticipated, but I did notice these two frames:

    请注意,它显示了六个可用的小部件可供选择.

    Note that it shows six available widgets to select from.

    然后有这个框架:

    它仅显示两个可用的小部件.

    It shows only two available widgets.

    据此,我推断这些部分可能具有一些功能,使开发人员可以限制其中允许使用哪些小部件. 是否可能需要做一些事情才能使我的小部件在默认部分(如下所示)中显示为选项?

    From that, I infer that sections may have some feature that allows developers to constrain which widgets are allowed in them. Is there perhaps something I need to do in order to allow my widgets to appear as options in the default section (the one shown below)?

    .

    .

    .

    .

    .

    .

    编辑#2:

    我研究了小部件约束并发现了这一点:

    I researched widget constraints a bit and found this: https://docs.kentico.com/k12/developing-websites/page-builder-development/creating-pages-with-editable-areas-in-mvc

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

    Specifically the section titled "Limiting widgets allowed in an editable area", which says the following:

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

    Since my view is not passing a parameter with a whitelist of widgets, all widgets should (in theory) be allowed:

    @* Index.cshtml *@
    @using Kentico.PageBuilder.Web.Mvc
    @using Kentico.Web.Mvc
    
    <h1>Rhythm Agency</h1>
    
    @Html.Kentico().EditableArea("main")
    

    因此有一个理论.对于将新的小部件添加到页面时,为什么我的新小部件没有显示为选项,我仍然不知所措.

    So there goes that theory. I'm still at a loss as to why my new widget isn't appearing as an option when adding new widgets to the page.

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

For the controller and widget to be recognized you need to put your controller in the '/Controllers' folder. I have my widget controllers located in the '/Controllers/Widgets' folder.

我遇到的问题包括没有在类名中添加后缀"Controller",以及小部件控制器不在"/Controllers"文件夹中的问题.

I had issues which included not having added the suffix 'Controller' in the class name and issues with the widget controller not being in the '/Controllers' folder.

您还不是在单独的项目中工作吗?因为这需要您在'AssemblyInfo.cs'中使用以下内容

Also you aren't working in an seperate project? Because this would need you to use the following in the 'AssemblyInfo.cs'

using CMS;
[assembly: AssemblyDiscoverable]

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

And make sure you have enabled the page builder feature in your kentico project. For example:

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();

    ...
}