In one of our ASP.NET Core 1.1 project, I'm getting the following error when rendering following View. I think I'm correctly following suggestions from SO users like @DarinDimitrov here
Error: Input string was not in correct format
ViewModel:
Public Class OrdersViewModel
{
....
[DisplayFormat(DataFormatString = "{(0:C)}")]
public float? price { get; set; }
}
View:
@model MyProj.Models.OrdersViewModel
@{
Layout = "";
}
....
<tr>
<td>Price:</td>
<td>@Html.DisplayFor(t => t.price)</td>
</tr>
UPDATE:
This @String.Format("{0:c}", Model.price) works as suggested here by @nemesv. But I don't want to use it in the view since ModelView is used at multiple places on various views. So I would like to keep using DisplayFor(...) at those places instead - as it's a bit simpler.