Unable to add Dynamic content control to page

Posted by varma9 on 22-May-2019 21:16

I am trying to add a Dynamic content control (widget) to a page pragmatically. it is adding the control to the the page with this message "This widget is no longer available since the module providing its content is deleted or deactivated.". when i click on "Edit" button of the widget i see "Error! Could not load designer view!". Here is my code, any one encountered this issue?

public static void AddCustomControltoPage()
{
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type landActionType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.landaction.LandAction");
var myCollection = dynamicModuleManager.GetDataItems(landActionType);


PageManager pageManager = PageManager.GetManager();

var mvcProxy = new MvcWidgetProxy();
mvcProxy.ControllerName = typeof(DynamicContentController).FullName;

var dynamicController = new DynamicContentController();
dynamicController.Model.ContentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.landaction.Landaction");
dynamicController.Model.ProviderName = ((Telerik.Sitefinity.Data.DataProviderBase)myCollection.First().Provider).Name;
dynamicController.ListTemplateName = "land action";
dynamicController.DetailTemplateName = "land action";
dynamicController.Model.SelectionMode = SelectionMode.SelectedItems;
dynamicController.Model.ContentViewDisplayMode = Telerik.Sitefinity.Web.UI.ContentUI.Enums.ContentViewDisplayMode.Detail;
dynamicController.Model.DisplayMode = ListDisplayMode.Limit;

var selectedDynamicItems = new DynamicContent[1];
selectedDynamicItems[0] = myCollection.FirstOrDefault<DynamicContent>();

dynamicController.Model.SerializedSelectedItemsIds = "[\"" + selectedDynamicItems[0].Id.ToString() + "\"]";

mvcProxy.Settings = new ControllerSettings(dynamicController);
mvcProxy.WidgetName = "land actions";


ModifyPageNativeAPI(mvcProxy);
}
public static void ModifyPageNativeAPI(Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy mvcWidget)
{
PageManager pageManager = PageManager.GetManager();

PageData page = pageManager.GetPageDataList()
.Where(pD => (pD.NavigationNode.Title == "CreatedbyAPI" && pD.Status == ContentLifecycleStatus.Live))
.FirstOrDefault();

//edit the page to add content block
var draftPage = pageManager.EditPage(page.Id);

var draftControl = pageManager.CreateControl<PageDraftControl>(mvcWidget, "T488B2CD1010_Col00");
draftPage.Controls.Add(draftControl);

//Save the changes
pageManager.PublishPageDraft(draftPage);
pageManager.SaveChanges();

}

All Replies

This thread is closed