November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
It should be possible to call an action method for a block in a layout file but you should use @Html.PropertyFor() to use EPiServer CMS built in flow for resolving controller.
Are you aware of the performance problems with child actions?
Could you describe the scenario a little bit more? There are many ways to stich this together so we may give you better advise if you try to explain the problem you want to solve and the issue you see with populating the view model with data needed for the header.
Hi @Fredrik Haglund ! I am trying to display banner (image) under main menu panel (like a logo, but in the centre). I would like to have possibility to change this image in the future in admin panel. Because now its a static image in Resourses folder of the project. So I would like to find best solution for displaying and administrating this one banner (image). I created block with image, created controller and view. Found example , where such block is a property of startpage and startpage model and in _Header this block is calling @Html.PropertyFor(x=>x.HeaderBanner).
Hi Oleh,
You can take a look at AlloyTech site, and how they solved this with Logo. You can use the same logic for banners.
Basically you need one inline block for Banner.
You can create it on the start page so that editors can change it.
In PageViewContextFactory, fetch the Banner from the StartPage and update your LayoutModel class.
And then in layout / header you can use @Html.PropertyFor(x => x.Layout.Banner) or something like that
Hi @Dejan Caric , thanks for answer, but I have one more question: is there some other way for dispaying such bunners? Is there possibility to display banners without sending LeyoutModel to layout / header ?
The reason it has to be handled a little bit diffrent is because it is going to be used on all pages of your site.
The ViewModel is a composite between the current pages data and all data fetched/calculated from start page (and other places) used on all pages in header and footer.
So, you allways need to have some code to get what to show in the header and footer but it can of course be done in other ways.
Another aproach would be to introduce another property on you viewmodel: StartPage (or SettingsPage if you have a separate settings page). Then you can just render properties from that page without any coding.
Note that you do have to tweak stuff to get on-page editing of these properties to work on the start page or settings page.
Hi Oleh,
Yes, there are other more or less painful ways, but I would go for LayoutModel approach because Render.Action is an "expensive" operation.
If the banner has to be displayed on Start Page only, then you could use RenderSection and a single property on your StartPageViewModel.
Otherwise, use LayoutModel :)
Hello, I am developing MVC Episerver Site. I am trying to find best solution for displaying top banner (image) near logo. I found one solution: create banner block type , create view and add bunner to Home Page (Start Page) class. Then send view model to _Layout (_Root) and display it.
Example:
_Root.cshtml
and then in Header.cshtml
But as for me sending view model to _Layout (_Root) view is bad idea. So is it possible for example call Block Action method in _layout (_Root) view like:
Any ideas ?