Is there an equivalent to Html.Raw in Blazor?

后端 未结 2 818
梦毁少年i
梦毁少年i 2020-12-29 01:11

I have some HTML that is stored in a string. How can I render it in a Blazor/Razor view without automatic HTML encoding?

2条回答
  •  感情败类
    2020-12-29 01:27

    Not right now, but will have it probably in the next version: Follow this.

    Workaround (from that issue):

    cshtml

        
    
        @functions{
            [Parameter] string Content { get; set; }
            private ElementRef Span;
    
            protected override void OnAfterRender()
            {
                Microsoft.AspNetCore.Blazor.Browser.Interop.RegisteredFunction.Invoke("RawHtml", Span, Content);
            }
        }
    

    index.html

        
    

提交回复
热议问题