Try our conversational search powered by Generative AI!

Blocks without controller – how to structure views?


I would like to know how to structure views for blocks without controllers.
Beneath comes the details…

Documentation states “In Visual Studio, add a partial view with the same name as your block type and based on your block model class, to the Views/Shared folder of your project.” and “For performance reasons, it is recommended to use partial views directly, and not controllers, for block types.”.

So this implies there will be lot of views just placed in Views/Shared.

It can be used IViewTemplateModelRegistrator or PartialContentController approaches but this ones will eliminate the performance benifits, won’t they?
Edited, Nov 22, 2017 14:03

I don't think you should be that worried about performance when using controllers for blocks. But if they're not needed, you should avoid them.

You can also create your own view engine and change how the partial views are discovered:

public class ViewEngine : RazorViewEngine
    private static readonly string[] AdditionalPartialViewFormats =

    public ViewEngine()
        this.PartialViewLocationFormats = this.PartialViewLocationFormats.Union(AdditionalPartialViewFormats).ToArray();

And in Application_Start in Global you can register your custom view engine:

ViewEngines.Engines.Add(new ViewEngine());
Nov 22, 2017 16:59

Someone did actually measure the difference

Nov 22, 2017 17:04

Great, both post are useful.

Nov 23, 2017 9:39

it's much more fun when you throw feature folders in the game...

Nov 28, 2017 23:36
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.