I want to have multiple div
with different background URLs.
My inline razor for this code seems to be wrong:
<table>
@foreach (var item in fa.get_albums()) {
<tr>
<td>
<div style="background-image:url('@item.picture');">
///something
</div>
</td>
</tr>
}
</table>
What's the right way to put inline razor in to background-imag:url()
?
Navigate to Structure > Pages. Edit the page where you want to display a background image. In the left navigation menu, click on General. At the bottom of the page, unravel the fieldset called Dynamic Background.
To download a background image, right-click the background image you want to download and click Save background as.... A Save Picture dialog box will appear, allowing you to select the directory in which you want to save the image.
The issue you have is that MVC will happily fix the relative paths inside an img src
attribute but not for style
. You should map that virtual path using Url.Content()
:
<div style="background-image:url('@Url.Content(item.picture)');">
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