SaaS CMS has officially launched! Learn more now.

Cannot register a template for an interface


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?





Oct 07, 2013 10:36

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

Oct 07, 2013 15:29

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

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


Oct 07, 2013 16:03

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:


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


Oct 08, 2013 10:12

Thanks Johan - That woks great :)

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.