title: How to return an empty list in View in ASP.NET
body: <p>I want to show all users with a specified role name. What I am doing is just specify a role name in the View. If this name exists then show all the related users (this works now), or display nothing (Exceptions arose here).
  <strong>Here is my code in controller:</strong></p>
  
  <pre><code>public ActionResult ViewUser(string roleName)
      {       
          var UsersContext = new ApplicationDbContext();
          var roleManager = new RoleManager&lt;IdentityRole&gt;(new RoleStore&lt;IdentityRole&gt;(new ApplicationDbContext()));
          if (roleManager.RoleExists(roleName))
          {
              var role = roleManager.FindByName(roleName).Users.First();
              var usersInRole = UsersContext.Users.Where(u =&gt; u.Roles.Select(r =&gt; r.RoleId).Contains(role.RoleId)).ToList();
              return View(usersInRole);
          }
          else
          {
              return View();
          }
  
      }
  </code></pre>
  
  <p><strong>Here is the code with a non-existing role name called "Worker" in View:</strong></p>
  
  <pre><code>@Html.ActionLink("Manage User", "ViewUser", "Home", new { @roleName="Worker"}, new { style = "color:white" })
  </code></pre>
  
  <p>The following screenshot is the result when I specify "Customer" which exists in database as the role name. If I specify another non-existing name, the result should have contained no user list.
  <a href="https://i.stack.imgur.com/UY9Ky.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UY9Ky.png" alt="enter image description here"></a></p>