EPiServer Area - Blocks controllers never hitting

Vote:
 

Dear all,

I am working on my first EPiServer project and really appreciate what I'm discovering day after day. :)

However, we have the need to migrate an existing .NET MVC website into EPiServer. So what we have done is integrate the EPiServers references into the existing classic MVC solution, which has worked like a charm. So we have now the main part of the website that is classic .NET MVC and we have define an area in the file structure specific to EPiServers, where we manage all the blocks definitions, the pages definitions, etc... As you can see below :

In this mixed solution, I can access the EPiServer's backend and create some content that I'm then able to access through the front-end of my website. We have already create a set of blocks that we are able to add on pages and have them working in front-end part. But now we need to start to add some dynamic behaviour like pagination into our blocks, so we need to integrate some logic for blocks, which should be done at the controller level of the block.

The problem is that my blocks controllers are never hitting, I can place some breakpoints into them, those one are never hitted. I guess this is because of this Area structure of my solution. For pages, EPiServer hits the controller, no worries, but not for blocks. But my page types are defined in the same way as my block types, so why is it working for pages and not for blocks?

Just one thing more, in order to have EPiServer front-end pages working in my mixed solution, I had to register the following area :

    public class CmsAreaRegistration : AreaRegistration 
    {
        public override string AreaName 
        {
            get 
            {
                return "Cms";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Cms_default",
                "Cms/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }

Then as I have said, pages controllers are working fine and I can display some EPiServer's content. Can you help me find the right way? Do I have to implement a custom blocks engine something like this?

Thanks in advance for your help, cheers,

#122989
Jun 22, 2015 15:14
Vote:
 

Converting a website to EPiServer can be quite tricky. Some things I think of checking are:

Initializing EPiServer

Lots of initialization of EPiServer also happens if your project's Global.asax inherits EPiServer.Global

EPiServer doesn't fully support Areas yet

Check these blog posts that might give you some ideas how to work with MVC and try to add Areas:

http://world.episerver.com/blogs/Tuan--Truong/Dates/2014/2/Upgrade-to-EPiServer-Commerce-75--Part-2-MVC-Areas-Support-For-EPiServer-7--above/

http://geta.no/blogg/full-support-for-asp.net-mvc-areas-in-episerver-7.5/

https://www.epinova.no/blog/tarjei-olsen/dates/2013/1/changing-view-folder-locations-in-episerver-cms7-mvc/

Controllers

If your controllers aren't found automatically, adding the TemplateDecriptorAttribute on your controllers might help finding them.

http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/8/Rendering/Rendering/

#123251
Jun 30, 2015 9:40
Vote:
 

I just saw that this was posted in 2015, I have no clue why it was at the top of the forum....

Episerver uses conventions to render blocks, it could be that you have named it as such and therefore your controller will be skipped.

Create a partial view without a controller, naming the view the same as the block type. If the view is chosen as the renderer of the block type, the view is called with the page data object directly, without controller involvement. This approach is the recommended way to render blocks.

Read more here: https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Block-types-and-templates/

#201756
Edited, Mar 01, 2019 10:51
* 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.