tags:

views:

240

answers:

1

I have an image from an Url.Action, like this

<img src="<%= Url.Action("Image") %>" alt="" />

How can I set this image as a background to a div? I tried this:

<div style="background-image:url(/Background/Image)"></div>

and others, but no success, I'm trying to play with JS over that div, and I need that background.

+1  A: 

Try using Url.Content. I was recently trying to do the same thing for my JavaScript files and I found out about Url.Content from this blog.

<script src="<%= Url.Content("~/Scripts/packed.js") %>"></script>

For your DIV, I'd do (shortened for readability):

<div style="background-image:url(<%= Url.Content("~/Bkd/img.jpg") %>)"></div>
JMP
Thank You! Problem solved:<div id="canvas" style="background-image:url(<%= Url.Content("~/Background/Image") %>)"> </div>
Andrei T. Ursan