我尝试执行以下操作
<script type="text/javascript">
var techIDs = "";
@if (ViewBag.URLParameters != null)
{
techIDs = '@ViewBag.URLParameters';
}
</script>
但这似乎是一种错误的做法。
有任何线索可以做到吗?
谢谢!
答案 0 :(得分:9)
试试这个
var techIDs = "";
@if (ViewBag.URLParameters != null)
{
@:techIDs = '@ViewBag.URLParameters';
}
答案 1 :(得分:2)
也许:
<script>
var techIDs = '@Html.Raw(ViewBag.URLParameters ?? String.Empty)';
</script>
答案 2 :(得分:1)
我找到了其他方法
var techIDs = "";
@if (ViewBag.URLParameters != null)
{
<text>techIDs = '@ViewBag.URLParameters' ;</text>
}