Meca
Meca

Reputation: 148

How to define the location of ViewComponent views during startup in a .net Core application?

I want to move the views out of the components folder under Pages into their own folder. Does this have to be defined in the startup? How is it defined?

For example:

The views are currently under: /Pages/Share/Components

I want to put them under: /Components

Upvotes: 1

Views: 256

Answers (1)

Edward
Edward

Reputation: 29976

For configuring the custom search location, you could try code below:

services.Configure<RazorViewEngineOptions>(o =>
{
    o.ViewLocationFormats.Add("/{0}" + RazorViewEngine.ViewExtension);
});

And then the project structure for Components like

  • Project
    • Components
      • View Component Name
        • View Name

Upvotes: 2

Related Questions