Reputation: 257
I'm trying to style some cards in an mvc project and i have a custom property(variable) in my css "--bg-img" file as shown :
background-image: linear-gradient(rgba(0, 0, 0, var(--bg-filter-opacity)), rgba(0, 0, 0, var(--bg-filter-opacity))), var(--bg-img);
and in the cshtml file my code looks like this :
<a class="card-posting-link posting-links" asp-action="details" asp-route-id="@item.Id" style="--bg-img: url('../../wwwroot/Uploads/@item.ImagePath')">
in vs code everything is fine, example :
<a class="card-posting-link posting-links" href="/#/" style="--bg-img: url(/Assets/image.jpeg)">
I tried:
~/Uploads
~/wwwroot/Uploads
and many other ways to get the images but nothing worked.
Upvotes: 1
Views: 219
Reputation: 257
The Solution was to add c# Url.Content bewfore the css adding the css url like this :
href="@Url.Content("~/wwwroot/Uploads/@item.ImagePath")" />
You can check the following link:
https://stackoverflow.com/a/48386317/15091527
Upvotes: 1