Cannot register a template for an interface

Vote:
 

I have a website which uses a repository for a contacts search.

I have created a partial router so I can have a virtual contact details page available after my contacts search page which is a page in the CMS.

The 'GetRecord' method in repository returns a type of iContact.

 

public class ContactPartialRouter : IPartialRouter<Models.Pages.ContactsSearchPage, IContactRecord>
    {
        public PartialRouteData GetPartialVirtualPath(IContactRecord content, string language, System.Web.Routing.RouteValueDictionary routeValues, System.Web.Routing.RequestContext requestContext)
        {
            // Get the content link  for the page context.
            var contentLink = ContentRoute.GetValue("node", requestContext, routeValues) as ContentReference;

            if (contentLink == null)
                return null;

            var t = new PartialRouteData
            {
                BasePathRoot = contentLink,
                PartialVirtualPath = content.Username
            };

            return t;
        }

        public object RoutePartial(Models.Pages.ContactsSearchPage content, EPiServer.Web.Routing.Segments.SegmentContext segmentContext)
        {
            // We need to remove the added trailing slash at the end that was added by EPiServer in GetPartialVirtualPath 
            var username = segmentContext.RemainingPath.TrimEnd('/');

            segmentContext.RemainingPath = string.Empty;
            segmentContext.RoutedContentLink = content.ContentLink;

            var repository = ServiceLocator.Current.GetInstance<IContactsRepository>();

            return repository.GetRecord(username);
        }
    }

When I register a template for the interface:

public partial class ContactPage : SimplePage, IRenderTemplate<Business.Interfaces.IContactRecord>  

I am returned a 404 not found error when navigating to a partially routed page.

 

When I register a template for a concrete instance of the interface:

public partial class ContactPage : SimplePage, IRenderTemplate<ActiveDirectoryContactRecord>

The template is returned with the data correctly.

 

Do I need to register the template differently to work with the interface? Is this a bug in EPiServer? Should it be possible to-do this?

 

Thanks,

Adam

   

#75794
Oct 07, 2013 10:36
Vote:
 

You need to have a templatedescriptor attribute on your template with Inherited=true

#75808
Oct 07, 2013 15:29
Vote:
 

Thanks Johan, I have tried the following and it does not work.

    [TemplateDescriptor(Inherited = true)]
    public partial class ContactTemplate : SimplePage, IRenderTemplate<Business.Interfaces.IContactRecord>

    

#75811
Oct 07, 2013 16:03
Vote:
 

You need to explicitly register your concrete modeltypes against TemplateModelRepository (this will be changed in CMS 7.5 so the explicit registration is not nessecary) like:

ServiceLocator.Current.GetInstance<TemplateModelRepository>().RegisterModelType(typeof(ActiveDirectoryContactRecord));

This is preferably done in a InitializationModule with module dependency to EPiServer.Web.InitializationModule

 

#75826
Oct 08, 2013 10:12
Vote:
 

Thanks Johan - That woks great :)

#75863
Oct 09, 2013 10:32
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.