Using Net.Core 7 I have a few View Components which are located in:
/Pages/Components/Component1/Default.cshtml
/Pages/Components/Component2/Default.cshtml
...
I want to place all views in Components folder and use the Component's name:
/Pages/Components/Component1.cshtml
/Pages/Components/Component2.cshtml
...
I was able to change the name from Default to Component1 using:
public IViewComponentResult Invoke() {
return View("Component1");
}
Can this be accomplish with a global configuration?
What about placing all in Components folder and not using one folder per component?
You can use RazorViewEngineOptions e.g.
Be careful about o.ViewLocationFormats.Clear() it may make the other mvc controllers not work