NoWar
NoWar

Reputation: 37672

Html.Display extension not outputting value

I use the following code to print user name.

@if (User.Identity.IsAuthenticated)
{
   @Html.Display("Welcome, " + User.Identity.Name);
}

But it doesn't print it.

Why?

Upvotes: 0

Views: 87

Answers (2)

NoWar
NoWar

Reputation: 37672

I found another solution:

 @if (User.Identity.IsAuthenticated)
           {
               <label>Welcome, </label>  @Html.Label(User.Identity.Name);
           }

Upvotes: 0

Sjoerd
Sjoerd

Reputation: 75699

Html.Display is not meant to display strings, but properties from your model. Try something like this:

@if (User.Identity.IsAuthenticated)
{
   @: Welcome, @User.Identity.Name
}

Upvotes: 4

Related Questions