C#C
C#2y ago
asloni

Preview Monaco editor input as html on blazor project

Hello i have a .net 8 blazor project where i want to write html inside the monaco code editor and then see it render live just below the editor. The problem is that im not shure about how events are handled coming from react. GPT is suggesting i use " @bind-Value="EditorValue"" but it the console then complains it cant find "value".

@page "/"

@code {
    private string EditorValue = "<div>hello</div>";

    private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
    {
        return new StandaloneEditorConstructionOptions
            {
                Value = EditorValue,
                AutomaticLayout = true,
                Language = "html",
                Theme = "vs-dark",
            };
    }
}

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

<StandaloneCodeEditor @bind-Value="EditorValue" CssClass="my-editor-class" Id="my-editor-instance-id" ConstructionOptions="EditorConstructionOptions" />
<div>@(new MarkupString(EditorValue))</div>


I might just be stupid but any help is appreciated,
Screenshot_2024-05-25_183200.png
Was this page helpful?