Aspnetcore: _ViewImports extravaganza

Created on 14 Mar 2019  路  2Comments  路  Source: dotnet/aspnetcore

This topic is used to discuss the issue and see how we can (maybe) change it.

It's starting to become a _ViewImports extravaganza!, the following is a default Razor Components Template (3.0.0 preview 3):

image

Personally I find the use of ViewImports handy but I'm always doubting in which file I should put my content (namespaces, layout etc). Can't we combine some viewimports or create a property on .razor files which specify their layout?

area-blazor question

All 2 comments

Thanks for contacting us, @vertonghenb.
The existence of _ViewImports.cshtml file is intentional per each view directory, as they are hierarchical: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout#importing-shared-directives. That helps a lot of customers to get started.
You can, of course, apply the layout in each of the .razor files, but that would become repetitive in case you have multiple files within the same directory, which should follow the same layout.
On the side note, we do plan to eventually get rid of one of the Pages directory in the project structure.

@vertonghenb - I agree, and this will change soon.

  1. Components are going to get their very own thing _Imports.razor
  2. We're simplifying some stuff in the template
  3. We'll be cleaning up/removing some namespaces which will help

@layout has to remain a directive because Components rendering is top-down. This means that we need to be able to know the layout before rendering a component - it has to be static. You can set @layout in any individual file, closest wins.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danroth27 picture danroth27  路  130Comments

Rast1234 picture Rast1234  路  104Comments

zorthgo picture zorthgo  路  136Comments

rmarinho picture rmarinho  路  78Comments

KerolosMalak picture KerolosMalak  路  269Comments