Razor 中的条件编译已关闭? [英] Conditional Compilation is turned off in Razor?

查看:25
本文介绍了Razor 中的条件编译已关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 c# foreach 循环,它输出一些 javascript 来初始化我的 razor 视图上的一些进度条.

I've got a c# foreach loop that Is outputting some javascript to initialize some progress bars on my razor view.

@foreach (var item3 in Model)
{
    @:$("#campaignMeter-@item3.ID").wijprogressbar({ value: @((item3.TotalRedeemed / item3.TotalSold) * 100), fillDirection: "east" });

}

我遇到的问题是 Visual Studio 在 foreach 循环中报告条件编译已关闭",尽管 TotalRedeemed 和 TotalSold 具有值,但对值的小计算始终为 0.我是否正确使用了 @: 运算符?感谢您的帮助.

The problem I'm having is visual studio is reporting "Conditional Compilation is Turned Off" on the foreach loop, and the small calculation for value is always coming out as 0, despite TotalRedeemed and TotalSold having values. Am I using the @: operator properly? Thanks for your help.

到目前为止,我已经尝试了这两种建议,这就是我目前所拥有的:

I've tried both suggestions so far and this is what I currently have:

 @foreach (var item3 in Model)
 {

     var percentage = (item3.TotalRedeemed / item3.TotalSold) * 100;

     <text>$("#campaignMeter-@item3.ID").wijprogressbar({ value: @percentage, fillDirection: "east" });</text>

 }

percentage 为 0,但 TotalRedeemed 和 TotalSold 有值,因为它们在调用之前打印在视图上.有没有办法在我的视图上设置断点以查看打印前的百分比?

percentage is coming out as 0, but TotalRedeemed and TotalSold have values, as they are printed on the view before this is called. Is there a way to set a break point on my view to see what percentage is before its printed?

推荐答案

在您的代码中添加 /*@cc_on @*/.

更新:发现为什么它们可以是 0:

Update: Found out why they could be 0:

item3.TotalRedeemeditem3.TotalSold 需要为 floatdouble.如果它们是 int,则结果为 0.

item3.TotalRedeemed and item3.TotalSold need to be float or double. If they are int, it comes out to 0.

这篇关于Razor 中的条件编译已关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆