November Happy Hour will be moved to Thursday December 5th.

PreviewController for shared blocks

Vote:
 

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):

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=64223

 

http://joelabrahamsson.com/pattern-for-episerver-block-preview-mvc-controller/

 

http://joelabrahamsson.com/pattern-for-episerver-block-preview-mvc-controller/

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=64774&epslanguage=en

 

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!

#73502
Jul 25, 2013 8:54
Vote:
 

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

http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=62993

#73503
Jul 25, 2013 8:56
Vote:
 

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

#73566
Jul 29, 2013 16:23
Vote:
 

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

#73568
Jul 29, 2013 20:24
Vote:
 

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

#73573
Jul 30, 2013 8:15
Vote:
 

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..

#73577
Jul 30, 2013 10:58
Vote:
 

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));

 

#73578
Jul 30, 2013 12:03
Vote:
 

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

#73580
Jul 30, 2013 13:04
Vote:
 

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?

#73581
Jul 30, 2013 13:18
Vote:
 

No, none. 

#73582
Jul 30, 2013 13:28
Vote:
 

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

#73620
Aug 01, 2013 10:08
Vote:
 

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.

#114653
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.