SaaS CMS has officially launched! Learn more now.

Render local block on every page


We are trying to add some functionality to our exsisting website. In this regard we need a local block on every page. I have created a block and have added it as property on PageBase class, this is the class which is inherited by every page. 

The problem i am having is how to render this block on every page without using @Html.PropertyFor(), on every page view.

public abstract class PageDataBase : PageData
            Name = "Test blok",
            Description = "",
            GroupName =,
            Order = 1)]
        public virtual TestBlock TestBlock { get; set; }

How to render TestBlock on everypage without adding 
@Html.PropertyFor(m=> m.CurrentPage.TestBlock) on every view of page
Aug 25, 2020 13:37

Hi ZZ,

The recommended way is to use @Html.PropertyFor so I think you should go with this approach only.

Aug 26, 2020 7:19

The issue I am having is that I have to add this to each and every view of the page. And if some one create a new page then the person should remeber to add this line too ? 

How can i do it explicitly for every page view ? 


Aug 26, 2020 7:23

depends on your scenario, but at the end in MVC world - markup that visitor receives is more or less in your own control. You can generalize local block generation either by inheriting from some base controller or implementing MVC filters or use any other mechanism to do it "transparently", but at the end - when it comes to "where should we render this block" - this is something that you have to specify. If this is something pretty global (like menu, headers, etc) - Layout is one of the place where this can be applied to every page on the site. 

But in your case - apply this rendering logic to all classes that inherit this specific page, guess there is no automatic way to include local block in every child page's view.

Aug 28, 2020 6:08
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.