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
Blazor components can be used in existing ASP.NET MVC applications.
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.
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"
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
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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With