0

Previous question for context (the previous question was going nowhere, so I created this new one to start fresh): Unable to Create New MVC Widget in Kentico 12

I'm trying to create a widget called "Image with Summary". For now, I'm just trying to add a single property to it (a summary property that will have a rich text editor).

It isn't appearing as a widget option when I add a new widget to page builder:

Page Builder with Widget Dialog

From this, you can see that I have page builder configured properly (there is already a "Rich text" widget added), you can see that adding widgets is possible (the "Rich text" widget comes from a NuGet package that I installed called "Kentico.EMS12.MvcComponents.Widget.RichText"), and you can see that I only have two widgets available ("Form" and "Rich text"), neither of which are the widget I'm trying to add.

I need your help figuring out why my new widget is not appearing in this dialog.

Here is the Solution Explorer in Visual Studio showing all the files I've created for this new widget:

Visual Studio Solution Explorer showing files related to Image with Summary widget

Here is what my properties class looks like:

// ImageWithSummaryProperties.cs
namespace RhythmAgency.KenticoWebsite.Widgets.ImageWithSummary
{
    using Kentico.PageBuilder.Web.Mvc;

    public class ImageWithSummaryProperties : IWidgetProperties
    {
        public string Summary { get; set; }
    }
}

Here is what my view model looks like:

// ImageWithSummaryViewModel.cs
namespace RhythmAgency.KenticoWebsite.Widgets.ImageWithSummary
{
    public class ImageWithSummaryViewModel
    {
        public string Summary { get; set; }
    }
}

Here is what my controller looks like:

// ImageWithSummaryController.cs
using System.Web.Mvc;
using Kentico.PageBuilder.Web.Mvc;
using RhythmAgency.KenticoWebsite.Widgets.ImageWithSummary;

[assembly: RegisterWidget(
    identifier: "Rhythm.ImageWithSummary",
    controllerType: typeof(ImageWithSummaryController),
    name: "Image with Summary",
    Description = "An image with summary text.",
    IconClass = "icon-l-img-3-cols-3")]

namespace RhythmAgency.KenticoWebsite.Widgets.ImageWithSummary
{
    public class ImageWithSummaryController : WidgetController<ImageWithSummaryProperties>
    {
        public ActionResult Index()
        {
            var properties = GetProperties();
            return PartialView("Widgets/_Rhythm.ImageWithSummary", new ImageWithSummaryViewModel()
            {
                Summary = properties.Summary
            });
        }
    }
}

Here is what my view looks like:

@* _Rhythm.ImageWithSummary.cshtml *@
@using Kentico.PageBuilder.Web.Mvc
@using RhythmAgency.KenticoWebsite.Widgets.ImageWithSummary
@using Kentico.Components.Web.Mvc.InlineEditors
@model ImageWithSummaryViewModel

@if (Context.Kentico().PageBuilder().EditMode)
{
    Html.Kentico().RichTextEditor(nameof(ImageWithSummaryProperties.Summary), null);
}
else
{
    <div class="fr-view">
        @Html.Raw(Html.Kentico().ResolveRichText(Model.Summary))
    </div>
}

I wouldn't focus too much on the view file, as I'm not even able to add the widget to the page builder, so the view has never even had a chance to be called.

Here's my home view file:

@* Views/Home/Index.cshtml *@
@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Web.Mvc

<h1>Rhythm Agency</h1>

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

I'm really at a loss as to why this widget isn't appearing in the list of available widgets to add to the page section. Here's some extra context:

  • I'm on Kentico 12.0.77.
  • I've tried a widget without a controller and now one with a controller.
  • As you can see, I have the widget registration (as an assembly attribute) in the controller class file.
  • The frontend of the site renders the rich text widget just fine.
  • I didn't see any relevant issues in the error log.
  • I'm using the default section.
  • When I call EditableArea, you can see I do not place any restrictions on the widgets that can be used.
  • I'm using the free edition of Kentico. I doubt that's a factor, but mentioning it just in case (the "benefits of upgrading your license" link is currently a 404).
  • I don't see any errors in Chrome's console.
  • I've read various instructions for creating widgets like 10 times. No idea what I'm missing.
  • I'm using Chrome on Windows 10.
  • I was previously calling the widget "Image Summary Section", but I renamed it on the off chance "Section" was a reserved word.

EDIT:

Somebody is curious as to why this and the previous question are different, so this edit clarifies that. The previous question was about a widget I was attempting to implement using just a properties class. This newer question uses a different approach (namely, using a controller), which is an alternative way of implementing widgets in Kentico.

EDIT #2:

Somebody recommended I put the widget registration assembly attribute in the App_Start folder, which I did, but it didn't help:

Widget Registration Code

So why this is failing to work is still a mystery.

Nicholas Westby
  • 1,109
  • 13
  • 32
  • Does this answer your question? [Unable to Create New MVC Widget in Kentico 12](https://stackoverflow.com/questions/62947063/unable-to-create-new-mvc-widget-in-kentico-12) – Brenden Kehren Jul 17 '20 at 19:32
  • The previous question was going somewhere, sometimes it just takes time to understand and communicate via text vs. in-person. Your initial question before all the updates was pretty generic and didn't have the detail after you updated it. I voted to mark this question as a duplicate because it doesn't help the community to have multiple questions for the same issue and solution. Continue to work on the other question to get a solution for it. – Brenden Kehren Jul 17 '20 at 19:35
  • Maybe I have to tell Kentico to scan the assembly in the first place? Not sure how I'd do that. I followed these instructions (to create the example NumberWidget) and it didn't work either: https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-widgets-in-mvc/example-developing-a-widget-in-mvc – Nicholas Westby Jul 17 '20 at 21:59
  • Update: Trying a full license ("Enterprise marketing solution" edition) rather than a free license didn't help. – Nicholas Westby Jul 17 '20 at 22:28

1 Answers1

1

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.

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.

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]

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

    ...
}
A. van Hugten
  • 715
  • 5
  • 16
  • Thank you! The assembly attribute "AssemblyDiscoverable' is exactly what I was missing (my widget wasn't in a separate project, but this attribute seems to be necessary anyway). That really ought to be part of the documentation for creating widgets. If you would like to post this answer on my previous question, I would be happy to mark it as the solution there as well. – Nicholas Westby Jul 18 '20 at 22:19