Reputation: 10713
In my MVC app, the images will b in the App_Data folder. I want to give the source to my img tag in Jquery. Here is how I do it:
var src1 = <%=Url.Content(Server.MapPath("/AppData/1.jpg"))%>
$("#imgLocation").attr("src", src1);
But it doesn't work. Why?
Upvotes: 6
Views: 50265
Reputation: 7591
try following:
var src1 = '<%=Url.Content(Server.MapPath("~/AppData/1.jpg"))%>';
$("#imgLocation").attr("src", src1);
Upvotes: 17
Reputation: 7536
Because you are trying do access an HTML element which is called imgLocation
You either have to use
$('#imgLocation')
if your img has an ID of id="imgLocation"
$('.imgLocation')
if your img has a class of class="imgLocation"
Upvotes: 3