简体   繁体   中英

How to call blazor onclick method with static render mode

How to call onclick method while rendering component as a static html? I mean, is there any workarounds in JavaScript?

@(await Html.RenderComponentAsync<Awesome>(RenderMode.Static))

And the Awesome.razor

<h3>@name</h3>

<button @onclick="@(() => name = name.ToUpper())">Upper case me</button>

@code {
    string name = "Mr. Blazor";
}

While using ServerPrerendered it seems to work because oninitialize method is fire, but again onclick doesn't work.

@(await Html.RenderComponentAsync<Awesome>(RenderMode.ServerPrerendered))

Like the docs say:

Static : Renders the component into static HTML

That means an @onclick will never work, nor anything else in written in C#.

is there any workarounds in JavaScript?

JavaScript will still work, use onclick (without the @ ). But that won't let you use this name variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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