SVG Base64String or bytes array to RazorPage

Jasonix 1 Reputation point
2021-04-30T08:22:05.06+00:00

Hi,
In my solution i have a base64 string (get it from a webservice) and i want to show this in a RazorPage.

How can I solve this?

Thanks :)

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,479 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,076 Reputation points Microsoft Vendor
    2021-05-03T05:02:43.213+00:00

    Hi Jasonix-8458,

    To display images (store as bytes array or base64 string) in the razor page, you could try to the following sample code: the ContentFile data type is byte[], we should transfer it to base64 string, then use an <img> tag to display the image:

            <div class="form-group col-4">  
                <label asp-for="ContentForoModel.ContentFile" class="control-label h2"></label>  
                @{  
                    var base64 = Convert.ToBase64String(Model.ContentForoModel.ContentFile);  
                    var Image = String.Format("data:image/svg+xml;base64,{0}", base64);  
                }  
                <img src="@Image" alt="" class="img-fluid">  
            </div>  
    

    The result like this:

    93167-capture6.png

    More detail code, you could refer the reply in this thread: How to display an image saved on database in .NET Core API?


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Dillion

    0 comments No comments