简体   繁体   中英

@Url.Content isn't found in my javascript file

I have the next line in my javascript file:

"<img alt=\"Active\" src=\"@Url.Content(\"~/Images/play.png\")\" />"

so I tried to do what AHM suggested in this topic ( @Url.Content in separate javascript file using ASPNET MVC 3 and Razor ):

var ROOT = "@Url.Content(\"~/";
"<img alt=\"Active\" src=\"" + ROOT + "Images/play.png\")\" />"

but I got an error:

Reports/@Url.Content( 404 (Not Found) 

what I did wrong?

any help appreciated!

@Url.Content is not supported in JavaScript file

In your code is wrong

var ROOT = "@Url.Content(\"~/"; <= parentheses is not closed & you donot need to escape quotes

Instead use in beginning of file

var ROOT = '@Url.Content("~/")';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM