Try our conversational search powered by Generative AI!

Block controller not used when rendering local block

Vote:
 

I'm upgrading to 7.5 and having some issues getting a block to work. I have a local block in a page type such as:

1 public virtual KeepUpdatedBlock KeepUpdated { getset; }

I render it using:

1 @Html.PropertyFor(x => x.CurrentPage.KeepUpdated)

The block has a controller:

01 public class KeepUpdatedController : BlockController<KeepUpdatedBlock>
02 {
03     public override ActionResult Index(KeepUpdatedBlock currentBlock)
04     {
05         KeepUpdatedViewModel model = new KeepUpdatedViewModel()
06         {
07            ...
08         };
09  
10         return PartialView("KeepUpdatedBlock", model);
11     }

Problem is, the controller is not obviously not used and I can't figure out why.

The model item passed into the dictionary is of type 'Castle.Proxies.KeepUpdatedBlockProxy', but this dictionary requires a model item of type 'xxx.Web.Models.ViewModels.KeepUpdatedViewModel'.

Clues? 

#81329
Feb 14, 2014 10:58
Vote:
 

You can hopefully get some more information if you turn on log4net logging on debug level for EPiServer.Web.TemplateResolver.

#81341
Feb 14, 2014 12:39
Vote:
 

If you take in a dependency to TemplateResolver somewhere you can probably do something like this to help you debug.

var Template = _templateResolver.Resolve(httpContext, typeof(KeepUpdatedBlock), currentBlock, TemplateTypeCategories.MvcPartial, YourRenderingTag);

#81342
Feb 14, 2014 12:46
Vote:
 

Thanks. I had some weirdness going on in my viewengine, that weren't visible in 7.0. Solved now!

#81366
Feb 14, 2014 20:06
Vote:
 

Beaware that if your block type name matches view name - your controller may have been omitted. You would need to decorate that with TemplateDescriptor or implement IRenderTemplate<T> somehow, or name your view as partial (for instance starting with "_") and return view from controller explicitly.

#81383
Feb 16, 2014 22:08
Vote:
 

Hi Thomaz, How did you resolved this issue. I got an error like yours today under upgrading. Could you give me a clue?

 

Thanks.

T.Dzung

#81996
Mar 03, 2014 12:49
Vote:
 

TDLA. I also just run into this and doing like Valdis said helped me. Meaning that I renamed my block to start with a _ (common MVC naming).

#82010
Mar 04, 2014 7:49
Vote:
 

Thank you Henrik! I just did like you/Vadis said and the error are gone, it's working! :-)

#82013
Mar 04, 2014 9:46
Vote:
 

Good to know TDLA!
Maby Thomas can mark my an Valdis answer as answer?

#82014
Mar 04, 2014 9:48
Vote:
 

We encountered this exact problem too, and Valdis answer gave the solution.

Maybe this should be changed so that the if you have created a custom controller for a block it is used even if there is a view matching the name?

#82714
Mar 18, 2014 15:09
Vote:
 

This design decision (to skip controller) was based on performance considerations. It's much faster to skip controller invoking than not to skip ;)

#82718
Mar 18, 2014 16:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.