title: Avoid duplicate records in ASP.NET MVC5
body: <p>I am new in ASP.NET so I have problem with duplicate records in my search enginee. When I search for the towns, some records are duplicate some of them are tree-douple.</p>
  
  <p><a href="https://i.stack.imgur.com/JYLc2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JYLc2.jpg" alt="Picture 1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/WFMA4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WFMA4.jpg" alt="Picture 2"></a></p>
  
  <p><strong>Controller.cs</strong></p>
  
  <pre><code>[Authorize(Roles = "Attorney")]
  public ActionResult CreateNext(int? id)
  {
      var currentUser = manager.FindById(User.Identity.GetUserId());
      var nfDoc = db.NFDOCUMENTS.Find(id);
  
  
      if (nfDoc.UserId == currentUser.Id &amp;&amp; nfDoc.FacilityId == null)
      {
          var contacts = db.Contacts.Where(x =&gt; x.ContactCategory.Name == "Facility");
          List&lt;string&gt; towns = new List&lt;string&gt;();
  
          foreach (var item in contacts)
          {
              if (!towns.Contains(item.City))
              {
                  towns.Add(item.City);  
  
  
              }
          }
  
  
  
          ViewData["towns"] = towns;
  
  
          var medProviders = db.Contacts.Where(x =&gt; x.ContactCategory.Name == "Facility" &amp;&amp; x.Firstname != null).ToList();
          ViewData["medProviders"] = medProviders;
  
          var pat = db.Patients.Where(x =&gt; x.Id == nfDoc.PatientId).FirstOrDefault();
          ViewBag.Address = pat.Address1 + ", " + pat.City + ", " + pat.State + ", " + pat.Zip;
          ViewBag.InsuranceId = new SelectList(db.Contacts.Where(s =&gt; s.ContactCategory.Name == "Insurance Carrier"), "Id", "Firstname");
          ViewBag.AdjusterId = new SelectList(db.Contacts.Where(s =&gt; s.ContactCategory.Name == "Adjuster"), "Id", "Firstname");
          ViewBag.FacilityId = new SelectList(db.Contacts.Where(s =&gt; s.ContactCategory.Name == "Facility"), "Id", "Firstname");
          ViewBag.DoctorId = new SelectList(db.Contacts.Where(s =&gt; s.ContactCategory.Name == "Doctor"), "Id", "Firstname");
  
          ViewBag.PatientId = pat.Id;
          ViewBag.PatientName = pat.Firstname + " " + pat.Lastname;
  
          return View();
      }
  
      else
      {
          return RedirectToAction("Create");
      }
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <p>SO I expect after searchin engine filted towns, I want to avoid duplicates</p>
  
  <pre><code>  &lt;div class="input-group col-md-12"&gt;
     &lt;input id="search" type="text" class="form-control input-lg" placeholder="Search towns" /&gt;
     &lt;/div&gt;
  &lt;ul class="list-group nav nav-pills nav-stacked" style="height: 200px; overflow-x: hidden; overflow-y: auto"&gt;
  &lt;li&gt;&lt;a class="reload-towns"&gt;&lt;i class="icon-location4"&gt;&lt;/i&gt; ALL TOWNS&lt;/a&gt;&lt;/li&gt;
    @foreach (var item in towns)
    {
   &lt;li&gt;&lt;a class="town" data-town="@item"&gt;&lt;i class="icon-location3"&gt;&lt;/i&gt; @item&lt;/a&gt;&lt;/li&gt;
  }
      &lt;/ul&gt;
            &lt;/div&gt;
                   &lt;/div&gt;
                         &lt;/div&gt;
  </code></pre>