n.shojaei n.shojaei - 7 months ago 51
CSS Question

Dynamic background-image

I want to have multiple

with different background URLs.
My inline razor for this code seems to be wrong:

@foreach (var item in fa.get_albums()) {
<div style="background-image:url('@item.picture');">

What's the right way to put inline razor in to


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)');">