Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP.NET MVC中写入@Html.Raw(Html.Debug)时出现语法错误_C#_Javascript_Asp.net Mvc_Asp.net Mvc 4_Razor - Fatal编程技术网

C# 在ASP.NET MVC中写入@Html.Raw(Html.Debug)时出现语法错误

C# 在ASP.NET MVC中写入@Html.Raw(Html.Debug)时出现语法错误,c#,javascript,asp.net-mvc,asp.net-mvc-4,razor,C#,Javascript,Asp.net Mvc,Asp.net Mvc 4,Razor,我试图在MVC中将C#代码与javascript结合起来,以便仅在调试模式下使用页面时启用“调试” 这里我得到一个错误: <script type="text/javascript"> $(document).ready(function () { Control.init( "@(ViewBag.Control)", @Html.Raw(Html.IsDebug() ? "true" : "false")

我试图在MVC中将C#代码与javascript结合起来,以便仅在调试模式下使用页面时启用“调试”

这里我得到一个错误:

<script type="text/javascript">
    $(document).ready(function () {
        Control.init(
            "@(ViewBag.Control)", 
            @Html.Raw(Html.IsDebug() ? "true" : "false")
            );
    });
</script>
当我这样做时:

"@(Html.IsDebug() ? "true" : "false")"
而不是:

@(Html.IsDebug() ? "true" : "false") 
工作,但是…:

<script type="text/javascript">
    $(document).ready(function () {
        Control.init(
            "Control1", 
            "true" // instead of true
            );
    });
</script>

$(文档).ready(函数(){
Control.init(
“控制1”,
“true”//而不是true
);
});

*更新:2013-11-27*

解决方案1:

<script type="text/javascript">
    $(document).ready(function () {
        Control.init(
            "@(ViewBag.Control)", 
            "@(Html.IsDebug() ? "true" : "false")" == "true"
            );
    });
</script>
<script type="text/javascript">


    $(document).ready(function () {
        @Html.Raw("Control.init("+ViewBag.Control+","+(Html.IsDebug() ? "true" : "false")+")")
    });
</script>

$(文档).ready(函数(){
Control.init(
“@(视图包控制)”,
“@(Html.IsDebug()?“true”:“false”)”==“true”
);
});
解决方案1:

<script type="text/javascript">
    $(document).ready(function () {
        Control.init(
            "@(ViewBag.Control)", 
            "@(Html.IsDebug() ? "true" : "false")" == "true"
            );
    });
</script>
<script type="text/javascript">


    $(document).ready(function () {
        @Html.Raw("Control.init("+ViewBag.Control+","+(Html.IsDebug() ? "true" : "false")+")")
    });
</script>

$(文档).ready(函数(){
@Html.Raw(“Control.init(“+ViewBag.Control+”,“+(Html.IsDebug()?“true”:“false”)+”)
});
试试这个

@{Html.Raw(Html.IsDebug() ? "true" : "false")}

这为我提供了所需的输出:

@(Html.Raw(Html.IsDebug() ? "true" : "false"))

你是如何实现IsDebug方法的?更新了,请检查我仍然有“语法错误”。。。我也试过@(Html.IsDebug()?“true”:“false”),但不起作用就不起作用。。。我不知道为什么,但如果我这样做的话:与“”相同的工作方式。。。比如:“@{Html.Raw(Html.IsDebug()?“true”:“false”);}”。。。但是我不想要'false'或'true',我想要'false'或'true',您可以始终将整个Control.init statemtn放入Html.Raw中,并使用字符串concat来构建整个语句,这样就可以了