It was mentioned at the start of the chapter that ASP.NET Core only includes one view engine, Razor, but nothing prevents us from adding more. This can be achieved through the ViewEngines collection of MvcViewOptions, as illustrated in the following code snippet:
services
.AddMvc()
.AddViewOptions(options =>
{
options.ViewEngines.Add(new CustomViewEngine());
});
A view engine is an implementation of IViewEngine, and the only included implementation is RazorViewEngine.
Again, view engines are searched sequentially when ASP.NET Core is asked to render a view and the first one that returns one is the one that is used. The only two methods defined by IViewEngine are as follows:
- FindView (ViewEngineResult): Tries to find a view from ActionContext
- GetView(ViewEngineResult): Tries to find a view from a path
Both methods return null if no view is found.
A view is an implementation...