Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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# 如果条件在Jquery中不起作用,为什么要查看包?_C#_Jquery_Asp.net Mvc - Fatal编程技术网

C# 如果条件在Jquery中不起作用,为什么要查看包?

C# 如果条件在Jquery中不起作用,为什么要查看包?,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,我正试图在jquery中获取一个支票ViewBag。它似乎起作用了。我添加了console.log和alert都不工作。我的代码有什么问题 /* Begin- Here we check if member credit card blocked */ bool isCCBlocked = membershipRenewal.CheckCCDeniedDemographic(memberId); ViewBag.IsCCBlocked = isCCBlo

我正试图在jquery中获取一个支票ViewBag。它似乎起作用了。我添加了
console.log
alert
都不工作。我的代码有什么问题

     /* Begin- Here we check if member credit card blocked */
        bool isCCBlocked = membershipRenewal.CheckCCDeniedDemographic(memberId);
        ViewBag.IsCCBlocked = isCCBlocked?"true":"false";
     /* End- Here we check if member credit card blocked */
JQuery

 $(document).ready(function () {
        // Checking if member credit card blocked    
        if (@ViewBag.IsCCBlocked.ToString().ToLower()==="true") {
            alert("IsCCBlocked");
        }
});

您可以在.cshtml文件中包含服务器端代码。。。服务器端代码前面必须有
@
符号。。。运行程序时,服务器端代码在服务器上执行,然后页面被呈现为HTML文件,并发送到客户端

由于要将
@ViewBag
的内容转换为字符串,因此需要将其置于引号中(因为字符串在.js中被引用),因此需要如下内容:

// this will generate something like: var isCCBlocked = 'true'; 
var isCCBlocked = '@ViewBag.IsCCBlocked.ToString().ToLower()'; 
if (isCcBlocked === "true") {
    alert("IsCCBlocked");
}

您可以在.cshtml文件中包含服务器端代码。。。服务器端代码前面必须有
@
符号。。。运行程序时,服务器端代码在服务器上执行,然后页面被呈现为HTML文件,并发送到客户端

由于要将
@ViewBag
的内容转换为字符串,因此需要将其置于引号中(因为字符串在.js中被引用),因此需要如下内容:

// this will generate something like: var isCCBlocked = 'true'; 
var isCCBlocked = '@ViewBag.IsCCBlocked.ToString().ToLower()'; 
if (isCcBlocked === "true") {
    alert("IsCCBlocked");
}

你刚刚错过了引号。试试这个
if(@ViewBag.IsCCBlocked?.ToString()?.ToLower()“==”true“){
或者如果(@ViewBag.IsCCBlocked.ToString().ToLower())?也就是说
如果(true)
出现这些问题,第一步总是
在浏览器中查看源代码。试试这个:如果('@ViewBag.IsCCBlocked'='true'){alert')(“IsCCBlocked”);}您刚刚错过了引号。请尝试此
if(@ViewBag.IsCCBlocked?.ToString()?.ToLower()”==“true”){
或者只
if(@ViewBag.IsCCBlocked.ToString().ToLower())
?例如
if(true)
对于此类问题,第一步始终是在浏览器中查看源代码。请尝试以下操作:如果('@ViewBag.IsCCBlocked'=='True'){alert(“IsCCBlocked”);}