【发布时间】:2012-08-25 11:00:56
【问题描述】:
我已经搜索过 SO 并没有找到解决此问题的方法。我有这样的代码:
<script>
$("AddToFavorites").Click(function() {
var apiLink = "/url/AddToFavorites?id=" + @Model.RecipeId;
$.ajax({
url: apiLink,
type: "GET"
});
});
</script>
.在 Model.RecipeId 中带下划线,我得到一个编译器错误:
Conditional compilation is turned off
难道不能在 javscript 块中使用 c# 代码吗?如果是这种情况,在这种情况下如何绕过它以使 url 动态化?
谢谢。
【问题讨论】:
-
将
Model.RecipeId放在单引号之间!
标签: c# javascript razor visual-studio-2012