I have an ASP.NET MVC RAZOR View. This view had the following:
@Html.LabelFor(m => m.Name)
That approach was working fine. But, I needed to add a check on the name field.So I started using:
@if (String.IsNullOrWhiteSpace(Model.Name)
{
<b>The name wasn't provided</b>
}
else
{
Html.LabelFor(m => m.Name);
<div>the name should appear</div>
}
Now, my label isn't appearing at all. In some cases, I'll see the "The name wasn't provided" like I expected. But, when a name is present, I see "the name should appear", but I do not see the actual name like I'd expect.
What am I doing wrong? It seems odd that just @Html.LabelFor(m => m.Name) worked as expected. But, once I added the check, it didn't.