I am using an if else in Razor view to check for null value like this:
@foreach (var item in Model)
{
-
You have to use the @()
@if (item.Amount == null)
{
@("--");
}
else
{
@String.Format("{0:0.##}", item.Amount)
}
As noted in the comments and other answers, the Html.Display
is not for displaying strings, but for displaying data from the ViewData
Dictionary or from a Model
. Read http://msdn.microsoft.com/en-us/library/ee310174%28v=VS.98%29.aspx#Y0
- 热议问题