1

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.