简体   繁体   English

Blazor 无法从其他文件夹中找到引用的组件

[英]Blazor can't find referenced component from other folder

I'm trying out Blazor WebAssembly, and wanted to create some new components on top of the pregenerated example project from Visual Studio.我正在尝试 Blazor WebAssembly,并希望在 Visual Studio 预生成的示例项目之上创建一些新组件。

So, essentially what I ended up is the following folder structure:所以,基本上我最终得到的是以下文件夹结构:

Project
\ Components
  \ Navigation
    \ BurgerMenu.razor
      BurgerMenu.razor.css
      BurgerMenu.razor.less
\ Shared
  \ MainLayout.razor
    MainLayout.razor.css
    MainLayout.razor.less

So far so good.到目前为止,一切都很好。 Here are my components:这是我的组件:

MainLayout.razor: MainLayout.razor:

@using Components.Navigation;

@inherits LayoutComponentBase

<div class="sidebar">
    <BurgerMenu />
</div>

<div class="LayoutContainer">
    @Body
</div>

BurgerMenu.razor:汉堡菜单.razor:

<div>
    Test Component
</div>

@code
{
}

As you can see, as of yet there is really nothing to write home about.正如你所看到的,到目前为止,真的没有什么可写的。

However, I can't get this to work properly.但是,我无法让它正常工作。 Every build complains regarding warning RZ10012: Found markup element with unexpected name 'BurgerMenu'. If this is intended to be a component, add a @using directive for its namespace.每个版本都会抱怨warning RZ10012: Found markup element with unexpected name 'BurgerMenu'. If this is intended to be a component, add a @using directive for its namespace. warning RZ10012: Found markup element with unexpected name 'BurgerMenu'. If this is intended to be a component, add a @using directive for its namespace.

So, I'm a bit lost now.所以,我现在有点迷路了。 Accoding to the official docs, the @using statement should be the proper way to import the component from a folder - Which is there.根据官方文档,@using 语句应该是从文件夹导入组件的正确方法 - 就在那里。 However, this still doesn't work.但是,这仍然行不通。

If I move the BurgerMenu.razor within the /Shared folder, everything works fine.如果我在 /Shared 文件夹中移动 BurgerMenu.razor,一切正常。

So, what am I doing wrong?那么,我做错了什么?

I'd have thought the using statement would need to include your project name:我原以为 using 语句需要包含您的项目名称:

@using Project.Components.Navigation;

If I try something similar to you the editor underlines the using statement (without the project name) in red.如果我尝试与您类似的事情,编辑器会用红色强调 using 语句(不带项目名称)。

This problem was fixed for my after restarting Visual Studio for me.为我重新启动 Visual Studio 后,此问题已解决。 I'm running Professional 2019 and apparently the intellesense gets stuck.我正在运行 Professional 2019,显然智能感知卡住了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM