Images with razor asp.net mvc inside JS

Posted by sarsnake on Stack Overflow See other posts from Stack Overflow or by sarsnake
Published on 2012-04-10T23:24:27Z Indexed on 2012/04/10 23:29 UTC
Read the original article Hit count: 209

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-3

Related posts about image