我在 javascript block 中使用以下 Razor 语句,但收到“True is undefined”运行时错误。 @Request.IsLocal 呈现为 True 的 bool 值。谢谢。
<script type="text/javascript">
var test;
if (@Request.IsLocal || @Request.IsLocal == 'True')
{
test = 'local';
}
else
{
test = 'not loccal'
}
alert(test);
</script>
最佳答案
True
不是 javascript bool 值。这是真实
尝试以下
<script type="text/javascript">
var test;
if ("@(Request.IsLocal)" == 'True')
{
test = 'local';
}
else
{
test = 'not loccal'
}
alert(test);
</script>
或者
<script type="text/javascript">
var test;
if (@Request.IsLocal.ToString().ToLowerInvarient())
{
test = 'local';
}
else
{
test = 'not loccal'
}
alert(test);
</script>
关于javascript - 在 javascript 脚本 block 中评估 Razor @Request.IsLocal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41969670/