Preview Custom Module content with custom MVC controller wid

Posted by Community Admin on 04-Aug-2018 00:11

Preview Custom Module content with custom MVC controller widget?

All Replies

Posted by Community Admin on 27-Apr-2016 00:00

Hope I'm asking this the right way - sorry if it's confusing.

In Sitefinity 8.2.59 we used the Module Builder to create a new custom module with a single data type in it.  We also built a custom MVC controller widget that's responsible for the presentation of the custom module's data type items.  This widget appears in the toolbox and we've added it to a page.  The widget provides list and detail views on the same page. 

However, when we're editing these custom data type items using the backend admin interface, the Preview button reports "No pages has been set to display content like this."

How do we make the association between our custom data type and the MVC widget we use to present them so that this feature will properly link to the page hosting an instance of the widget?

Thanks.

Posted by Community Admin on 28-Apr-2016 00:00

Hi, 

By default Sitefinity uses the IContentLocatableView interface implemented on the out of the box content widgets in order to track their locations on different pages. This interface powers the Preview functionality from the content modules as well as the Search indexing and the correct resolving of the links in it. 
When you click on the Preview button of a built-in content item, Sitefinity searches the page where you have placed the module's widget and then renders the item on its details page.

Regarding custom controls, the Preview functionality will work only if these controls implement the IContentLocatableView interface. Implementing this interface in your control will basically tell the Preview button where this type of content is placed on the site and will redirect to this location in order to display the content.

After you implement the IContentLocatableView interface in your MVC controllers, the Preview button will redirect to the url of the module's details page. 

Please refer to the documentation for more details:
Register content location with your custom widgets
http://docs.sitefinity.com/for-developers-register-content-location-with-your-custom-widgets


Locations of content items
docs.sitefinity.com/for-developers-locations-of-content-items

Here is also a sample code for your convenience on how this interface is implemented for dynamic module. You can further modify this on your end and make it to work for the content type you need:

 
public bool? DisableCanonicalUrlMetaTag
       
           get;
           set;
       
   
       public IEnumerable<IContentLocationInfo> GetLocations()
       
           var location = new ContentLocationInfo();
   
           Type testType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Test.Test");
           location.ContentType = testType;
   
           var manager = DynamicModuleManager.GetManager();
           var providerName = manager.Provider.Name;
           location.ProviderName = providerName;
   
           yield return location;
       


Regards,
Dimitri Cools
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 28-Apr-2016 00:00

That sounds like just the ticket, thanks!  I had seen that interface as it relates to search, but didn't realize there was a relationship between it and locating controllers for custom content preview.  I will give it a try and if/when it works I'll come back and mark this answered.  Thanks again.

Posted by Community Admin on 06-Mar-2017 00:00

Hi, I tried to follow the steps here but it doesn't seem to work? The page cannot be found.

My custom widget is a Master-Detail widget, maybe that is the reason? I only have one controller for both the Master and the Detail views. How do I specify in my controller that the Preview should point to the Detail view?

Thanks.

This thread is closed