Render local block on every page

ZZ
ZZ
Vote:
 

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
    {
[Display(
            Name = "Test blok",
            Description = "",
            GroupName = PropertyGroupNames.xxx,
            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
#226991
Aug 25, 2020 13:37
Vote:
 

Hi ZZ,

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

#227031
Aug 26, 2020 7:19
ZZ
Vote:
 

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 ? 

Thanks

#227032
Aug 26, 2020 7:23
Vote:
 

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.

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