I unable create an image widget with custom controller.
I copied all souce code used to build Image widget
in Dancing Goat example.
There is no error from my source code, but I got this error message after I click Image widget from Kentico CMS:
An error has occurred. If the problem persists, contact your system administrator.
I don't know where error accurred with my Image widget, no error happen if I click another widgets as: Text or Number widget.
After copied Image widget in Dancing Goat example, I just custom my controller as below:
using System;
using System.Linq;
using System.Web.Mvc;
using CMS.DocumentEngine;
using Kentico.PageBuilder.Web.Mvc;
using News.Controllers.Widgets;
using News.Models.Widgets;
using News.Models.Widgets.ImageWidget;
[assembly: RegisterWidget("News.Widgets.ImageWidget", typeof(ImageWidgetController), "Photo", Description = "Add a Photo", IconClass = "icon-picture")]
namespace News.Controllers.Widgets
{
public class ImageWidgetController : WidgetController<ImageWidgetProperties>
{
/// <summary>
/// Creates an instance of <see cref="ImageWidgetController"/> class.
/// </summary>
/// <param name="outputCacheDependencies">Output cache dependencies.</param>
/// <summary>
/// Creates an instance of <see cref="ImageWidgetController"/> class.
/// </summary>
/// <param name="propertiesRetriever">Retriever for widget properties.</param>
/// <param name="currentPageRetriever">Retriever for current page where is the widget used.</param>
/// <param name="outputCacheDependencies">Output cache dependencies.</param>
/// <remarks>Use this constructor for tests to handle dependencies.</remarks>
public ImageWidgetController(IComponentPropertiesRetriever<ImageWidgetProperties> propertiesRetriever, ICurrentPageRetriever currentPageRetriever)
: base(propertiesRetriever, currentPageRetriever)
{
}
public ActionResult Index()
{
var properties = GetProperties();
var image = GetImage(properties);
return PartialView("Widgets/_ImageWidget", new ImageWidgetViewModel
{
Image = image
});
}
private DocumentAttachment GetImage(ImageWidgetProperties properties)
{
var page = GetPage();
return page?.AllAttachments.FirstOrDefault(x => x.AttachmentGUID == properties.ImageGuid);
}
}
}
Basically, I only remove CacheDependencies
.
Can someone help me?