I have the following code within a razor mvc3 view that is duplicated in a couple of grids and tables to color code values:
@{var val= @@item.value * 100);}
@if(@val < 85) { <div style='color: #C11B17' > @val.ToString("0.0")%</div> }
@if(@val >= 85 && osi <=95 ) { <div style='color: #AF7817' > @val.ToString("#.0")%</div> }
@if(@val > 95 && osi <=115) { <div style='color: green' > @val.ToString("#.0")%</div> }
@if(@val > 115) { <div style='color: blue' > @val.ToString("#.0")%</div> }
How can I re-write to an equivalent lambda function so I can reuse within my view?
You can write this method in a non-rendered block and call it as needed:
Now you can call the method anywhere in that template: