从viewbag获取价值以折叠面板

时间:2016-12-27 02:16:47

标签: jquery html asp.net-mvc collapse viewbag

我必须得到一个折叠类名称的字符串,并将其带到视图以切换面板。 到目前为止,我设法使用ViewBag.collapse将字符串带到View,但我无法弄清楚如何切换它。 我尝试过像

这样的东西
<script>
  $("@ViewBag.collapse").collapse("toggle");
</script>

但它不起作用

1 个答案:

答案 0 :(得分:0)

由于collapse变量引用了CSS类,所以你需要做的只是在类名之前添加句点,所以它呈现像var obj = {}; var qsum_total_sales = 'SELECT SUM (total_price) AS s_total_price FROM myrecords'; var qsum_count_active = 'SELECT COUNT (*) AS s_count_active FROM myrecords WHERE NOT status = "canceled" '; var qdata = 'SELECT * FROM myrecords'; router.get('/data', function(req, res) { connection.query(qdata, function(err, result) { if (err) { throw err; } else { obj = { print: result }; console.log(obj); connection.query(qsum_total_sales, function(err, rows, result1) { if (err) { throw err; } else { rsum_total_sales = JSON.parse(rows[0].s_total_price).toFixed(2); console.log(rsum_total_sales); connection.query(qsum_count_active, function(err, rows2, result2) { if (err) { throw err; } else { rsum_count_active = JSON.parse(rows2[0].s_count_active); console.log(rsum_count_active); //After successful completion of all 3 queries send data back to cliend(front-end) //its better to create new obj everytime and send it //store all the data in obj and send back to client var obj = {}; obj.print = result; obj.rsum_count_active = rsum_count_active; obj.rsum_total_sales = rsum_total_sales; res.render('data', obj); } }); } }); } }); });

.collapse-target

现在它正试图找到匹配的HTML元素作为HTML标记,而不是类名。