In Index view I want to check if an object's parameter is null. I have done it as following code.
<td>
@if (String.IsNullOrEmpty(item.Account.Name) == false)
{
@Html.ActionLink(item.Account.Name, "../Accounts/Details", new { id = item.Account.AccountID })
}
else
{
@Html.DisplayFor(modelItem => item.Account.Name)
}
</td>
And I get this error:
{"Object reference not set to an instance of an object."}
So how should I check if the parameter in null?
1-ActionLink generates error if the object is null but DisplayFor does not.
2-This is in foreach loop in Index view.