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" });
}
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 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?
Add
/*@cc_on @*/in your code.Update: Found out why they could be
0:item3.TotalRedeemedanditem3.TotalSoldneed to befloatordouble. If they areint, it comes out to0.