Images with razor asp.net mvc inside JS
- by sarsnake
I need to dynamically insert an image in my JS code. In my Razor template I have:
@section Includes {
<script type="text/javascript">
var imgPath = "@Url.Content("~/Content/img/")";
alert(imgPath);
</script>
}
Then in my JS I have:
insertImg = "";
if (response[i].someFlag == 'Y') {
insertImg = "<img src=\"" + imgPath + "/imgToInsert.gif\" width=\"6px\" height=\"10px\" />";
}
But it doesn't work - it will not find the image. The image is stored in /Content/img folder...
What am I doing wrong?