PreviewController for shared blocks


I have a solution in where I use some shared blocks that can be put into ContentArea. Everything works fine, even in edit mode, except for one thing: When I create a new block or try to edit one I get the following exception:

Content with id '237_394' is of type 'Castle.Proxies.LinkBlockProxy' which does not inherit required type 'EPiServer.Core.PageData'

Some google searches pointed me towards making a PreviewController that inherits from IRenderTemplate<BlockData>, but none of the solutions I could find have worked so far. These are the different controller types I have tried (and permutations of them):


Here's a codesample from Joel Abrahamsson that I have tried with no luck:

[TemplateDescriptor(Inherited = true,
Tags = new []{RenderingTags.Preview},
TemplateTypeCategory = TemplateTypeCategories.MvcController)]
public class PreviewController : Controller, IRenderTemplate<BlockData>
    public ActionResult Index(IContent currentBlock)
        return PartialView(currentBlock);

Something is being registered, because with this in my code, I can no longer edit or create new blocks - I simply get a blank page. But the Index action is never called. Why doesn't this work? I am completely out of ideas, so if anyone got any suggestions, I would really appriciate it!

Jul 25, 2013 8:54

Oops.. Posted one of the links twice. Was supposed to be this one:

Jul 25, 2013 8:56

I'm guessing that you probably should be returning a view, not a partial view.

Jul 29, 2013 16:23

No, that's not it. Like I said, the Index action is never called. So what I return doesn't matter..

Jul 29, 2013 20:24

Could it be that you have some global action filter that is cancelling the Index action??

Jul 30, 2013 8:15

Well, I have one custom action filter registered + one for System.Web.Mvc.HandleErrorAttribute. The OnActionExecuting method of my custom action filter is called a bunch of times, but it eventually stops getting called (probably a lot of EPiServer things going on in the background). I've tried commenting out the registration of both actionfilters. No luck, so I don't think that's the problem. Good suggestion though - I hadn't thought of that possibility..

Jul 30, 2013 10:58

If you attach a debugger and selects all templates registered for the block type, what do you get back? Especially is your PreviewController in the list. Are there any other renderers of type MvcController or WebFormsPage.

You could get all templates for a model by calling:

var templates = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<TemplateModelRepository>()
.List(typeof (LinkBlock));


Jul 30, 2013 12:03

It finds the PreviewController and it has TemplateTypeCategory set to MvcController.

I don't know how easy it is to see from this, but here's the template variable expanded in the debugger:

- templates {EPiServer.DataAbstraction.TemplateModel[1]} System.Collections.Generic.IEnumerable<EPiServer.DataAbstraction.TemplateModel> {EPiServer.DataAbstraction.TemplateModel[]}
- [EPiServer.DataAbstraction.TemplateModel[]] {EPiServer.DataAbstraction.TemplateModel[1]} EPiServer.DataAbstraction.TemplateModel[]
- [0] {EPiServer.DataAbstraction.TemplateModel} EPiServer.DataAbstraction.TemplateModel
AvailableWithoutTag false bool
Default false bool
Description null string
DisplayName null string
Inherit true bool
Inherited true bool
IsReadOnly true bool
Name "PreviewController" string
Path null string
+ Tags {string[1]} string[]
+ TemplateType {Name = "PreviewController" FullName = "BWG.Intern.Web.Controllers.PreviewController"} System.Type {System.RuntimeType}
TemplateTypeCategory MvcController EPiServer.Framework.Web.TemplateTypeCategories
+ Non-Public members

Jul 30, 2013 13:04

That looks correct.

If you open up a console window in your browser, do you see any javascript errors when selecting to edit the block?

Jul 30, 2013 13:18

No, none. 

Jul 30, 2013 13:28

Could the "Path" field in the template variable above have something to do with it? It's set to null..

Aug 01, 2013 10:08

I just encountered the same issue. Turns out my layout expected a different model than the preview-view, hence the error. 

I know this is an old post, but I feel this should be here in case someone else hit this post while looking for a soution to the same error.

Dec 17, 2014 9:55
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.