1

The Microsoft Blazor render modes documentation says we can programmatically set the RenderMode for a component like:

@rendermode renderModeForPage
...
@code {
    private static IComponentRenderMode renderModeForPage = InteractiveServer;
}

I want to be able to dynamically switch the mode from static to InteractiveServer, but I can't work out how to set the page to Static SSR (which would be the default). I can only set renderModeForPage to InteractiveServer, InteractiveWebAssemmbly or InteractiveAuto, which implies we can't programmatically set a component to Static SSR? It won't allow me to set rendermode to null.

2
  • Not sure what the use case is for this, but you can't change it at runtime. If you were to explain why, we might be able to help you. Commented Feb 14, 2024 at 12:44
  • I'm building something along the lines of a mini CMS, where I want the pages to be served with static SSR, but if the user is logged in display a button they can click to open a modal to edit details for the page. The main page (not the modal) needs to change rendermode in this example if the user is logged in, so the button click event will fire to open the modal edit component. Commented Feb 14, 2024 at 14:03

1 Answer 1

1

You could try this workaround put the codes in a "child" component.

@page "/"
@if (IsSSR)
{
    <Child></Child>
}
else
{
    <Child @rendermode=renderModeForPage></Child> //Don't specify rendermode in child
}

@code{
    private static IComponentRenderMode renderModeForPage = InteractiveServer;
    private bool IsSSR = true;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.