【发布时间】:2023-03-22 12:11:01
【问题描述】:
我们有一个现有的 asp.net 项目,我的系统中有一份副本,
一个asp.net核心项目的正常结构,如下:
-Project
-- Properties
-- Areas
-- Controllers
-- Views
-- ...
部分代码将使用 blazor 服务器端,但我遇到了一个奇怪的问题。
我在 stratup.cs 文件中添加了所需的服务:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
});
接下来在项目结构的根目录中,我添加了一个用于 blazor 导入的文件:
_Imports.razor
内容:
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
然后尝试创建 blazor 组件,如“~/Components/Pages/Component.razor” 创建剃刀文件后,我意识到@page 或@code 关键字带有红色下划线,表示语法错误
我尝试在“~/Views/_ViewImports.cshtml”中添加命名空间:
@using MyProjectFullName.Components.Pages
通常,组件的命名空间源自应用的根命名空间和组件在应用内的位置(文件夹)。如果应用的根命名空间是 BlazorSample,并且 Counter 组件位于 Pages 文件夹中:enter link description here
但在尝试构建项目时出现此错误:
所有这些在我的系统中都可以正常工作,但是当在其他系统中执行相同操作时,我会收到有关命名空间或@page/@code 关键字的错误。
两个 Visual Studio 版本相同 -2019- 我们使用的是 netcore 3.1.402
我用谷歌搜索了几天,但找不到可行的解决方案。
【问题讨论】:
标签: asp.net-core blazor-server-side asp.net-blazor