title: ASP.NET MVC 4 Razor - Trying to find the username of a user
body: <p>All Code</p>
  
  <pre><code>@foreach (var item in Model)
  {
  &lt;div class="Comment-Box"&gt;
      &lt;p&gt;@item.UserId&lt;/p&gt;
      @(Membership.GetUser(item.UserId.ToString()).UserName)
        @if (Membership.GetUser() != null)
          {
             if(User.IsInRole("Admin") || item.UserId == (int)Membership.GetUser().ProviderUserKey){
                  @Html.ActionLink("Delete", "DeleteComment", new { id=item.Id })
             }
          }
  &lt;/div&gt;
  }
  </code></pre>
  
  <p>Problem Code</p>
  
  <pre><code> @(Membership.GetUser(item.UserId.ToString()).UserName)
  </code></pre>
  
  <p>The problem is when I access this page the method returns null and doesn't find the user name, I'm new to ASP.Net and MVC 4 and was just wondering why it doesn't work? and how to get around it.
  Any response would be appreciated. </p>