I have page that will show some currency data. I want to format the data with currency format but only using Display Template.
I have the following code:
@foreach (var item in Model.Data)
{
<tr class="@(item.Group%2==0? "odd-colore": "even-colore")">
<td>@Html.DisplayFor(modelItem => item.Name)</td>
<td>@Html.DisplayFor(modelItem => item.Amount1)</td>
<td>@Html.DisplayFor(modelItem => item.LName)</td>
<td>@Html.DisplayFor(modelItem => item.Amount2)</td>
<td>@Html.DisplayFor(modelItem => item.Amount3)</td>
</tr>
}
I have created a DisplayTemplate
String.cshtml
, since my datatype is string:
@model string
@{
IFormatProvider formatProvider = new System.Globalization.CultureInfo("en-US");
<span class="currency">@Model.ToString("C",formatProvider)</span>
}
But when I run it, I'm getting the error:
No overload for method 'ToString' takes 2 arguments
How can I display positive amount as $1000.00 and negative amount as ($1000.00) either using DisplayTemplate
or string.Format("{0:C}")