繁体   English   中英

Razor 组件未呈现

[英]Razor Component not rendering

我有一个简单的 Razor 组件。 应用程序构建,但是当我运行它时,没有显示任何内容。

Razor 组件 (SystemNameLookup.razor) 是

@inherits SystemNameLookupComponent
<h3>Hi @SystemName</h3>

后面的代码是

namespace WebApp.Pages.Shared.Components
{
    public class SystemNameLookupComponent : ComponentBase
    {
        [Parameter]
        public string SystemName { get; set; } = "Something";
    }
}

它被称为

<SystemNameLookup></SystemNameLookup>

_Imports.cshtml 包含

@using Microsoft.AspNetCore.Components
@using WebApp.Pages.Shared.Components

并且 _ViewImports.cshtml 包含

@using WebApp
@using WebApp.Pages.Shared.Components
@namespace WebApp.Pages

但是什么都没有出现? 我错过了什么。 (未报告错误 - 这是在 ASP.Net Core 5 上运行的)

I test with my blazor project,and it can work.Here is a demo(My project name is BlazorApp_ServerSide,and I don't have _ViewImports.cshtml in my blazor app,you can refer to the link , The _Imports.razor file is similar to the _ViewImports.cshtml file for Razor views and pages but applied specifically to Razor component files. ):

结构体:

在此处输入图像描述

SystemNameLookup.razor:

@inherits SystemNameLookupComponent
<h3>Hi @SystemName</h3>

SystemNameLookupComponent.razor.cs:

namespace BlazorApp_ServerSide.Pages.Shared.Components
{
    public class SystemNameLookupComponent: ComponentBase
    {
        [Parameter]
        public string SystemName { get; set; } = "Something";
    }
}

_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.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using BlazorApp_ServerSide
@using BlazorApp_ServerSide.Shared
@using Microsoft.AspNetCore.Components
@using BlazorApp_ServerSide.Pages.Shared.Components

测试.razor:

@page "/test"
<SystemNameLookup></SystemNameLookup>

结果: 在此处输入图像描述

暂无
暂无

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

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