I am working on a asp.net mvc 3 application and I've made several partial views each one responsible for rendering of specific logic. Inside one of my views I use properties which can be null, but I don't want to pass null to the @Html.DisplayFor()
and write something more user friendly to the user to know that these fields are not missing, they just don't have nothing assigned to them yet.
So I try this :
<tr>
<td>
@if (!string.IsNullOrEmpty(Model[0][0].FieldValue))
{
@Html.DisplayFor(Model => Model[0][0].FieldValue)
}
</td>
<td>
@Html.DisplayFor(Model => Model[1][0].FieldValue)
</td>
</tr>
I don't have else
clause because writing the if
statement results in getting both Model =>
in the DisplayFor
marked with red and the following message :
A local variable named 'Model' can not be declared in this scope because it would give a different meaning to 'Model' which is already used in a 'parent or current' scope to denote something.
Basically I think I understand what this error means however I don't know how to check for null properly in this situation.