ASP.Net MVC, How to set image from action link as <div> background?
I have an image from Url.Action like this
<img src="<%= Url.Action("Image") %>" alt="" />
How do I set this image as the background for a div? I've tried this:
<div style="background-image:url(/Background/Image)"></div>
and others but not success, I am trying to play with JS over this div and I need this background.
+2
source to share
1 answer
Try using Url.Content. I recently tried to do the same for my JavaScript files and I found out about Url.Content from this blog post .
<script src="<%= Url.Content("~/Scripts/packed.js") %>"></script>
For your DIV, I would do (short for readability):
<div style="background-image:url(<%= Url.Content("~/Bkd/img.jpg") %>)"></div>
+1
source to share