-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BlockIndex and GetDisplayOption helper does not return any value #59
Comments
Can you check in IoC (StructureMap) which Content area renderer is registered? Easily visible via Episerver Developer Tools |
Thanks for the reply! When I try to install the DeveloperTools in the Episerver project using nuget the project builds ok but I get an error saying that the file could not be loaded when loading the website. Using version 3.5. Tried using Alloy with Episerver 11.12 as well. "Could not load file or assembly 'EPiServer.DeveloperTools' or one of its dependencies. The system cannot find the file specified." Regarding the EPiBootstrapArea, it seems to be the correct content area renderer registered since other EPiBootstrapArea functionality is working. |
I tried to install EPiBootstrapArea using an empty Alloy website and there it seems to be working, at least in the basic configuration. I'll try and troubleshoot if there's any EPiBootstrapArea configuration that might interfere. |
Ok that's weird for developertools. I'll take a look later. If it's working correctly in alloy - might be some config in your project. |
No, not using the advanced-cms content review plugin but thinking about it. Thanks for the tip. The thing that seems to happen in the BlockIndex htmlhelper is that htmlHelper.ViewData does not contain any keys so looking for the "BootstrapContentArea__BlockIndex" will return -1. Regarding dependency injection, I take it that BootstrapAwareContentAreaRenderer sets up it's own DI in the SetupBootstrapRenderer class, so no manual DI configuration is needed, is this correct? |
Yes, that's correct, no manual DI is needed. |
For me changing the code like this make it works again:
I guess it's because in our project, we're using dedicate block controller instead of just registering a block with a partial view. |
v5.3 is on the way to the feed |
If others have similar issues, it could be custom block controllers messing this up.
|
Yeah, don’t think `ViewData` is inherited by default.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: Jonas ***@***.***>
Sent: trešdiena, 2021. gada 27. oktobris 11:14
To: ***@***.***>
Cc: valdis ***@***.***>; State ***@***.***>
Subject: Re: [valdisiljuconoks/EPiBootstrapArea] BlockIndex and GetDisplayOption helper does not return any value (#59)
If others have similar issues, it could be custom block controllers messing this up.
I ended up reading the value in the controller and extending the BlockViewModel.
Maybe there is some way to pass ViewData from ParentActionViewContext on to make the Html.GetIndex()-helper work, but didn't investigate it any further.
[TemplateDescriptor(Default = true, Inherited = true)]
public class DefaultBlockController : BlockController<BaseBlockData>
{
public override ActionResult Index(BaseBlockData currentBlock)
{
var model = CreateModel(currentBlock);
var blockName = currentBlock.GetOriginalType().Name;
model.BlockIndex = int.Parse(ControllerContext.ParentActionViewContext.ViewData["BootstrapContentArea__BlockIndex"]?.ToString() ?? "-1");
return PartialView(string.Format("~/Features/Blocks/{0}/{1}.cshtml", blockName, blockName), model);
}
private static IBlockViewModel<BlockData> CreateModel(BlockData currentBlock)
{
var type = typeof(BlockViewModel<>).MakeGenericType(currentBlock.GetOriginalType());
return Activator.CreateInstance(type, currentBlock) as IBlockViewModel<BlockData>;
}
}
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fvaldisiljuconoks%2FEPiBootstrapArea%2Fissues%2F59%23issuecomment-952652683&data=04%7C01%7C%7C33f44563e3eb42ceaf2108d99921d1e4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637709192798308142%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=vM5nRL3fsQPuuvG9e50AEzrCrysf6Q31aNsPoFCDHwc%3D&reserved=0>, or unsubscribe<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAANPOC3G74V3D7YGOBVIEC3UI67H3ANCNFSM4KIEP2PA&data=04%7C01%7C%7C33f44563e3eb42ceaf2108d99921d1e4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637709192798318128%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=JtfVzJgcD2%2BTKeLlVa1PFvrcxGo01BMRPJxTD%2F7F9%2Fs%3D&reserved=0>.
|
I'm trying to get the block index and selected display option for a block, but the block index always returns -1 och GetDisplayOption() returns an empty string.
I'm using in the html helpers in the view, like so:
@Html.GetDisplayOption(Model)
@Html.BlockIndex()
Any idea why this is?
I'm using Episerver 11.13.2.
The text was updated successfully, but these errors were encountered: