Hi
Just wanted to share something I found that might help someone else going forward or perhaps someone knows a better way of doing it.
Im running Optimizely CMS 12+ with Razor Pages and the new "/Features" structure from Foundation and was experiencing routing issues with the
FormcontainerBlock partial or specific Elementblocks after installing Optimizely Forms.
I could render the built in element types in the default FormContainer but when creating a custom FormContainer Block the application couldnt find the FormContainerBlock partial:
@await Html.PartialAsync("FormContainerBlock", Model) - Resulted in partial not found error
To fix this I had to add path: ~/FormsViews/Views/ElementBlocks/Components/{0}/{0}.cshtml
to my ViewExpander since the FormContainerBlock.cshtml partial is now in below "Views/ElementBlocks/Components/FormContainerBlock/"
in the Episerver.Forms module
Foundation view expander example (running MVC): https://github.com/episerver/Foundation/blob/main/src/Foundation/Infrastructure/Display/FeatureViewLocationExpander.cs
Example:
Startup.cs
services.AddRazorPages(opt => opt.RootDirectory = "/Features")
.AddRazorOptions(ro => {
ro.ViewLocationExpanders.Add(new FormsViewLocationExpander());
});
FormsViewLocationExpander.cs
public class FormsViewLocationExpander : IViewLocationExpander
{
private readonly List<string> _viewLocationFormats = new List<string>()
{
"~/FormsViews/Views/ElementBlocks/{0}.cshtml",
"~/FormsViews/Views/ElementBlocks/Components/{0}/{0}.cshtml",
};
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (viewLocations == null)
{
throw new ArgumentNullException(nameof(viewLocations));
}
var expandedLocations = viewLocations.Union(_viewLocationFormats);
foreach (var item in expandedLocations)
{
yield return item;
}
}
public void PopulateValues(ViewLocationExpanderContext context)
{
return;
}
}