我的javascript文件中有下一行:
"<img alt=\"Active\" src=\"@Url.Content(\"~/Images/play.png\")\" />"
所以我尝试执行本主题@Url.Content in separate javascript file using ASPNET MVC 3 and Razor)中建议的AHM
:
var ROOT = "@Url.Content(\"~/";
"<img alt=\"Active\" src=\"" + ROOT + "Images/play.png\")\" />"
但是我收到了一个错误:
Reports/@Url.Content( 404 (Not Found)
我做错了什么?
任何帮助表示赞赏!
答案 0 :(得分:1)
@Url.Content
你的代码错了
var ROOT = "@Url.Content(\"~/"; <= parentheses is not closed & you donot need to escape quotes
而是在文件开头
中使用var ROOT = '@Url.Content("~/")';