Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

c# - NET core 3.1 project + Razor Class Library

I′m trying to build a RCL (Razor Class Library), my idea is to generate a repository of UI components (just like a react components library) and let the users include these UI components in their apps. All apps are NET core 3.1 (All coded in C# and razor for the views). So with this library I intend to let the users include the new components in those apps.

So far I have the following

  • RCL project

  • NET core 3.1 with razor pages project (I want to create some sort of UI showcase, to indicate the usage of the component, how it looks, etc)

For simplicity lets say I have this component in my RCL project, MyComponent.razor

<h3>@id</h3>
<button class="btn btn-primary" @onclick="IncPress">INC</button>
<button class="btn btn-danger" @onclick="DecPress">DEC</button>
@code {
[Parameter]
public int id { get; set; }

public void IncPress()
{
    id = id + 1;
}

public void DecPress()
{
    if (id > 0)
    {
        id = id - 1;
    }
}}

In my Net core 3.1 + razor project I tried to render MyComponent.razor like this

Net core = 3.0

 @(await Html.RenderComponentAsync<MyComponent>(RenderMode.ServerPrerendered, new { id = 100}))

Net core >= 3.1

 <component type="typeof(MyComponent)" render-mode="ServerPrerendered" param-id="100" />

The component is rendering fine (but not working properly)

I have two questions regarding this

  1. Is this a feasible way of working ? I mean creating a RCL library to allow users to include components in their .net core apps?
  2. MyComponent does not update state if I click on the buttons. The id variable does not increment nor decrement, I think it has to do with the rendermode.
question from:https://stackoverflow.com/questions/66047092/net-core-3-1-project-razor-class-library

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...