November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
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 = { "~/Views/{0}/Partials/Index.cshtml", "~/Views/Shared/PagePartials/{0}.cshtml", "~/Views/Shared/Partials/{0}.cshtml", "~/Views/Shared/Blocks/{0}.cshtml", }; 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());
Someone did actually measure the difference https://hacksbyme.net/2017/09/26/performance-when-using-controllers-for-blocks/
I would like to know how to structure views for blocks without controllers.
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?