Custom Razor Viewer in MVC 6

I am doing some prototypes in .NET 5 MVC 6 and am trying to figure out where to register my own razor view engine. MVC 6 no longer has a global.asax file for registering custom objects. It has a startup.cs file which I would guess is the place to add it, but I'm not sure if this is the right place to do this and which method to call.

I current has its own razor viewer which looks something like

public class MyCustomerViewEngine : RazorViewEngine
{
    public MyCustomerViewEngine()
    {
        //My custom view stuff
    }
}

      

Any help would be greatly appreciated.

+3


source to share


1 answer


In the Startup.cs file

Go to method ConfigureServices

.



services.AddMvc(); // Replace this with following

services.AddMvc().Configure<MvcOptions>(options =>
{
    options.ViewEngines.Add(new MyCustomerViewEngine ());
});

      

+6


source







All Articles