Try our conversational search powered by Generative AI!

Block controller not used when rendering local block


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         };
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'.


Feb 14, 2014 10:58

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

Feb 14, 2014 12:39

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

Feb 14, 2014 12:46

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

Feb 14, 2014 20:06

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.

Feb 16, 2014 22:08

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




Mar 03, 2014 12:49

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

Mar 04, 2014 7:49

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

Mar 04, 2014 9:46

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

Mar 04, 2014 9:48

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?

Mar 18, 2014 15:09

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

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.