Reputation: 111
I am very new to .NET and am using MVC 4. I have a variable "AvgAnnualGrowth" of type double. This variable can have positive or negative values. When it is negative, I should display "-" before the data and when its positive, I should display "+" before the data. There is no problem with the negative data as the double variable displays "-" by default. For positive values, it does not display "+" explicitly. Any ideas on how to concatenate "+" in front of the data?
Following is the code snippet from my (view) cshtml file.
@foreach (var item in Model)
{
<tr>
<td align="right">
@Html.DisplayFor(modelItem => item.AvgAnnualGrowth)
</td>
</tr>
}
Upvotes: 2
Views: 2745
Reputation: 20674
You could label just before the DisplayFor
@Html.Label(item.AvgAnnualGrowth > 0 ? "+" : "")@Html.Display...
Upvotes: 2