title: Make a required field if the other field has value
body: <p>I have these variables:</p>
  
  <pre><code>public int? BossId { get; set; }
  public DateTime? HeadShipDate { get; set; }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.BossId, htmlAttributes: new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownList("BossId", null, "-- Select --", htmlAttributes: new { @class = "form-control" })
          @Html.ValidationMessageFor(model =&gt; model.BossId, "", new { @class = "text-danger" })
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="divDate" class="form-group"&gt;
       @Html.LabelFor(model =&gt; model.HeadShipDate, htmlAttributes: new { @class = "control-label col-md-2" })
       &lt;div class="col-md-10"&gt;
           @Html.EditorFor(model =&gt; model.HeadShipDate, new { htmlAttributes = new { @class = "form-control" } })
           @Html.ValidationMessageFor(model =&gt; model.HeadShipDate, "", new { @class = "text-danger" })
       &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Script (What I was trying to make required if BossId has a value):</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          HeadShipDate: {
                  required: {
                      depends: function(element){
                          return $("#BossId").text() != '-- Select --';
                      }
                  }
          }
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Create([Bind(Include = "Id,Name,Acronym,Percentage,BossId,HeadShipDate")] Department department)
  {
      Seller boss = db.Sellers.Find(department.BossId);
      if (boss.AdmissionDate &gt; department.HeadShipDate)
          ModelState.AddModelError(string.Empty, "Headship Date (" + department.HeadShipDate.Value.ToShortDateString() + ") must be greater than the Admission Date (" + boss.AdmissionDate.ToShortDateString() + ") of boss");
      else if (ModelState.IsValid)
      {
          boss.DeptId = department.Id;
          db.Departments.Add(department);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  
      ViewBag.BossId = new SelectList(SellersNonBosses(), "Id", "Name", department.BossId);
      return View(department);
   }
  </code></pre>
  
  <p>I want to make the HeadShipDate required field IF BossId has a value, in other works, if the text of DropDownList isn't "-- Select --", AND I want to make that validation (that condition I made in controller, checking headship date with admissionDate of that specific seller(Boss)) with JavaScript, how can I make this?</p>