Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show image in Blazor view

Tags:

blazor

I am trying show images in a Blazor view, but it's not working and shows only an image icon:

<img src="~/Images/watch.jpg" asp-append-version="true" width="300px" />

Here my image resides in this path wwwroot/Images/watch.jpg

like image 223
Parin Patel Avatar asked Sep 02 '18 10:09

Parin Patel


People also ask

Can you use MVC with Blazor?

Blazor components can be used in existing ASP.NET MVC applications.

What is Blazor view?

While Blazor is a framework, Razor, or Razor Pages, is a templating (View) engine. The Razor syntax combines Razor markup, C#, and HTML to create dynamic web content. Typically, Razor is used for powering ASP.NET MVC Views.

How do I add a logo to a Blazor website?

Create a folder images under wwwroot then access it like src="images/MyLogo.png" In Blazor, it appears that you don't require a relative path or even the wwwroot part. If your image is in wwwroot/images something like the following will work, (where class is a css that sets your image height) img class="my_logo-img" src="/images/myLogoImage.png"

What is the point of native development in Blazor?

Basically, it highlights the whole purpose of blazor development feeling a bit more like C# and less like Web, giving you the ability to reference items in the project by simple folder directory navigation without having to think about how the user's browser needs to access the resource. Pretty cool. #nativeDev

Is there a more efficient way to pass data in Blazor CLI?

As of Blazor 0.5 there not more efficient ways to pass data. As of version 0.5.0 the CLI package targets .NET Core 2.1 rather than .NET Core 2.0. You will have to update the ...<TargetFramework>... element in your csproj file to ...netcoreapp2.1... if you want to use this pacakge....I wonder though, why would you take a dependency on this package?

How do I make HTTP requests in Blazor server?

Blazor Server apps use a dedicated HttpClient service to make requests. If you haven't already added an HttpClient to the app's service collection, do so now by adding builder.Services.AddHttpClient (); in the Program.cs file before builder.Build (). For more information, see Make HTTP requests using IHttpClientFactory in ASP.NET Core.


1 Answers

You are probably running into this bug: https://github.com/aspnet/Blazor/issues/1216 and need to remove the ~ to make it work, or wait for the 0.6 release.

like image 64
Flores Avatar answered Oct 22 '22 05:10

Flores