title: MVC5 Display Data From Database Returning Null In View
body: <p>I am not sure what is wrong, in my home controller I am collecting the data from the database and assigning it to a model</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public ActionResult Index()
          {
              //Edited For Security Reasons
              UserManager.Manager manager = new UserManager.Manager();
  
              var data = manager.GetAllUsers();
              var userDetails = from u in data
                                select new UserDetail
                                {
                                    UserID = u.Id,
                                    Username = u.Name,
                                    UserLogin = u.Login,
                                    FirstName = u.FirstName,
                                    Surname = u.Surname,
                                    Email = u.Email,
                                    Active = Convert.ToInt32(u.Active),
                                    RightID = u.RightsId,
                                    GroupID = u.GroupsId,
                                };
              userDetails.ToList();
              return View();
          }
  </code></pre>
  
  <p>This is populating the userDetails as it has the values when I click it after leaving a breakpoint at <code>return View();</code></p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class UserDetail
  {
      public int UserID { get; set; }
      public string Username { get; set; }
      public string UserLogin { get; set; }
      public string FirstName { get; set; }
      public string Surname { get; set; }
      public string Email { get; set; }
      public int Active { get; set; }
      public List&lt;int&gt; RightID { get; set; }
      public List&lt;int&gt; GroupID { get; set; }
  }
  </code></pre>
  
  <p>Visual Studio is telling me the problem is with my <code>@foreach (var item in Model)</code> that it is returning <code>null</code> but i don't understand how it can be <code>null</code> when it is being populated in the Home Controller.</p>
  
  <p><strong>View</strong></p>
  
  <pre><code>@model IEnumerable&lt;WebApplication1.Models.UserDetail&gt;
  
  &lt;table class="table" id="tbData" cellspacing="5" border="1"&gt;
      &lt;tr&gt;
          &lt;th&gt;UserID&lt;/th&gt;
          &lt;th&gt;UserLogin&lt;/th&gt;
          &lt;th&gt;FirstName&lt;/th&gt;
          &lt;th&gt;Surname&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Active/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;@Html.DisplayFor(model =&gt; item.UserID)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(model =&gt; item.UserLogin)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(model =&gt; item.FirstName)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(model =&gt; item.Surname)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(model =&gt; item.Email)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(model =&gt; item.Active)&lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  
  <p>Thanks for your help in advance</p>