New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move MainLayout to another folder #5661

Open
UrielMhezzek opened this Issue Dec 2, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@UrielMhezzek

UrielMhezzek commented Dec 2, 2018

I use Blazor as server variant.
If I put the file MainLayout.cshtml into another folder, the old namespace is still used in the .g.cs files. Creating a different layout file also seems to lead to the fact that it has to be present in the shared folder.

@michaelvolz

This comment has been minimized.

michaelvolz commented Dec 2, 2018

@UrielMhezzek I renamed my MainLayout.cshtml into AppLayout.cshtml and moved it to the root. I moved all the files from Shared into Pages and renamed Pages to Features. For every component I created a subfolder with everything related to this component in it. Even JavaScript and CSS/SCSS. It is very convenient to work with.

You have to change the 2 _ViewImports.cshtml files accordingly to make it work.
One needs to have the correct Layout name and the other needs to have the correct namespaces corresponding to the folder structure.

Important: The Layout has to be outside of the Pages/Features folder. I am not exactly sure why.

Everything for one feature in only one defined place.
Feature Folder Structure in ASP.NET Core

@UrielMhezzek

This comment has been minimized.

UrielMhezzek commented Dec 4, 2018

@michaelvolz I'm using a technique very similar to the one you linked.
First i moved NavMenu and SurveyPromot to \Components\Shared to have all components found in one Folder for better overview. No more component is in shared-folder. No more component is in shared folder.

I changed the name like you. I get no error. But I moved only my AppLayout in to the root. I used Drag n Drop in Solution Explorer.

I get on every component a Debug-Message like this:

obj\Debug\netstandard2.0\Components\Shared\NavMenu.g.i.cs(22,19,22,25): error CS0234: The type or namespace name 'Shared' does not exist in the namespace 'DSA.App' (are you missing an assembly reference?)

obj\Debug\netstandard2.0\Components\Shared\SurveyPrompt.g.i.cs(22,19,22,25): error CS0234: The type or namespace name 'Shared' does not exist in the namespace 'DSA.App' (are you missing an assembly reference?)

I looked into the generated file. In every file i found this code

using DSA.App.Shared;
    [Microsoft.AspNetCore.Blazor.Layouts.LayoutAttribute(typeof(MainLayout))]

I removed the @using DSA.App.Shared in _ViewImports.cshtml. This work fine.

I moved the File to \component\shared and add @using DSA.App.Components.Shared in _ViewImports.cshtml. But i geht a blank side and no error.

@michaelvolz

This comment has been minimized.

michaelvolz commented Dec 4, 2018

@UrielMhezzek It seems, it still wants the MainLayout instead of the now renamed AppLayout. The _ViewImports.cshtml inside your components folder should include @layout AppLayout.

@UrielMhezzek

This comment has been minimized.

UrielMhezzek commented Dec 4, 2018

I changed the name back to MainLayout and i get the blank side, too.

@danroth27

This comment has been minimized.

Member

danroth27 commented Dec 5, 2018

@UrielMhezzek I'm not able to reproduce this issue based on the steps you provided. When you build the project from VS does it build cleanly? Could you please provide the project to us that reproduces the issue?

@aspnet-hello aspnet-hello transferred this issue from aspnet/Blazor Dec 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment