question

Jasonix-8458 avatar image
0 Votes"
Jasonix-8458 asked ZhiLv-MSFT edited

SVG Base64String or bytes array to RazorPage

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 :)

dotnet-aspnet-core-blazor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ZhiLv-MSFT avatar image
0 Votes"
ZhiLv-MSFT answered ZhiLv-MSFT edited

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






capture3.png (515.5 KiB)
capture6.png (90.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.