locked
如何调用 RazorClassLibrary 组件 RRS feed

  • 问题

  • 1、创建 Razor 类库,命名为 RazorClassLibrary1,目标框架 .net 5.0,不勾选 支持页面和视图,创建。

    2、创建 ASP.NET Core Web 应用,命名为 WebApplication1,目标框架 .net 5.0,勾选 配置 HTTPS(H), 勾选 Enable Razor runtime compilation,创建。

    3、WebApplication1 右键,生成依赖项,勾选 RazorClassLibrary1,确定。添加,项目引用,勾选 RazorClassLibrary1,确定。

    4、右键 Pages ,添加 Razor 组件,命名为 ConsumeComponent1.razor。代码如下:

    @page "/consume-component-1"
    
    <h1>Consume component (full namespace example)</h1>
    
    <RazorClassLibrary1.Component1 />

    在 Index.cshtml 的页面,要怎么才能调用 <RazorClassLibrary1.Component1 /> 或 ConsumeComponent1.razor,请问:该怎么设置?



    项目地址:https://github.com/Sg3361382/RazorClassLibrary1.git

    2021年8月25日 9:29

答案

  • 您好,

    我认为您需要做三个步骤:

    1.在 ~/Imports.razor 文件中导入RazorClassLibrary1.

     @using RazorClassLibrary1

    2.打开~/Startup.cs 文件并从RCL 注册Blazor 服务.

    3.将组件加入index 页面.

     <Component></Component>

    您可以参考以下文档. https://blazor.syncfusion.com/documentation/getting-started/razor-class-library

    2021年8月26日 6:43