Search code examples
c#asp.net.netasp.net-mvcasp.net-core-viewcomponent

Searching paths for ViewComponent in ASP.NET


In general if we use View("Index"). It will search for views in Views/ControllerName or Views/Shared folder. Likewise if we use Component.InvokeAsync("SomeData") then what are the paths it will search for that viewcomponent


Solution

  • Since it is a component, runtimes will search into components folder as stated below:

    • /Views/{Controller Name}/Components/{View Component Name}/{View Name}
    • /Views/Shared/Components/{View Component Name}/{View Name}
    • /Pages/Shared/Components/{View Component Name}/{View Name}

    source: microsoft docs