title: How to Check if record exist in database using Entity Framework in ASP.NET MVC razor?
body: <p>Is it possible for a controller to check if record exists in database using ADO.NET?</p>
  
  <p>Here is my controller</p>
  
  <pre><code>[HttpPost]
  public ActionResult Add(TemporaryVoucher temporaryVoucher)
  {
      string fileName = Path.GetFileNameWithoutExtension(temporaryVoucher.ImageFile.FileName);
      string extension = Path.GetExtension(temporaryVoucher.ImageFile.FileName);
      fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
  
      /*temporaryVoucher.VoucherPath = "/Image/" + fileName;
      fileName = Path.Combine(Server.MapPath("/Image/"), fileName);*/
      temporaryVoucher.VoucherPath = fileName;
  
      using (DBModels db = new DBModels())
      {
          db.TemporaryVouchers.Add(temporaryVoucher);
          db.SaveChanges();
      }
  
      ModelState.Clear();
      return View();
  }
  </code></pre>
  
  <p>Here is my ado.net in model</p>
  
  <pre><code>public partial class TemporaryVoucher
  {
      public int PromoKey { get; set; }
      public string PromoName { get; set; }
      [DisplayName("Upload Image")]
      public string VoucherPath { get; set; }
  
      public HttpPostedFileBase ImageFile { get; set; }
  }
  </code></pre>
  
  <p>Here is my view</p>
  
  <pre><code>&lt;div class="form-group"&gt;
          @*Html.LabelFor(model =&gt; model.ImageName)*@
          &lt;label name="PromoName" style="text-align: right; clear: both; float:left;margin-right:15px;"&gt;PromoName&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              @*Html.EditorFor(model =&gt; model.ImageName, new { htmlAttributes = new { @class = "form-control", required = "required" } })
                  @Html.ValidationMessageFor(model =&gt; model.ImageName, "", new { @class = "text-danger" })*@
              &lt;input type="text" name="PromoName" id="txtInput" onkeypress="return checkSpcialChar(event)" required /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @*Html.LabelFor(model =&gt; model.ImagePath, htmlAttributes: new { @class = "control-label col-md-2" })*@
          &lt;label name="ImagePath" style="text-align: right; clear: both; float:left;margin-right:15px;margin-top:5px;"&gt;Upload Image&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input type="file" style="margin-top:5px;" name="ImageFile" accept=".jpg,.jpeg,.png" required /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Upload" style="margin-top:5px;" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I just want to ensure no possible duplication for PromoName in the database</p>