Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

How to make blocks without controllers work in feature folders

$
0
0

I am trying to use feature folders for my first EPiServer site build and running into an issue with blocks. I can get blocks to work fine that have controllers, but for some reason using blocks without controllers does not work. I get the message that the block cannot be displayed when rendered on a page. Add the controller and it works just fine, even without specifying a path to the view so I know the view resolution logic is working. There is no logic in the controller, just a call to PartialView(model) which I want to avoid for the sake of performance. I followed some articles online on how to create a view engine to add the additional paths for feature folders, shown below:

public SiteViewEngine()
{
   var additionalLocations = new[]
      {"~/Features/{0}.cshtml","~/Features/{1}/{0}.cshtml","~/Features/{1}/{1}.cshtml","~/Features/{1}/Views/{0}.cshtml","~/Features/{1}/Views/{1}.cshtml","~/Features/Shared/{0}.cshtml","~/Features/Shared/Views/{0}.cshtml"
      }
      .Union(FeatureFolders())
      .ToArray();
   ViewLocationFormats = ViewLocationFormats.Union(additionalLocations).ToArray();
   MasterLocationFormats = MasterLocationFormats.Union(additionalLocations).ToArray();
   PartialViewLocationFormats = PartialViewLocationFormats.Union(additionalLocations).ToArray();
}

Viewing all articles
Browse latest Browse all 9076

Trending Articles