title: Validate input data from a DropDown depending of a DatePicker on another PartialView
body: <p>I have some trouble with my ASP.NET MVC project.</p>
  
  <p>I'm trying to check if the choice selected by a user in a <em>DropDown</em> is valid. This depends entirely of a date (chosen by the user) on another tab.</p>
  
  <p>I have my <strong>OfferController</strong> which renders <strong>FormView</strong> (with <strong>Offer</strong> as a model). <strong>FormView</strong> contains 2 or 3 tabs, each one being a <em>PartialView</em> with it's own model.</p>
  
  <p>I want to check a <em>DateTime</em> value entered on the first tab (<strong>VehicleView</strong> with <strong>VehicleDetails</strong> as model) to send an error message if needed on the second tab (<strong>WarrantyView</strong> with <strong>Warranty</strong> as model). This message has to be shown immediately when the user selects an incorrect item in the <em>DropDown</em>.</p>
  
  <p>The model <strong>Offer</strong> contains both <strong>VehicleDetails</strong> and <strong>Warranty</strong>.</p>
  
  <p>Others validations (using <em>annotations</em>) are working fine.</p>
  
  <p>I've tried creating a <em>CustomValidator</em> as explained <a href="http://www.ezzylearning.com/tutorial/creating-custom-validation-attribute-in-asp-net-mvc" rel="nofollow noreferrer">here</a> but I couldn't get the updated value for the date from <strong>VehicleDetails</strong>.</p>
  
  <p>I also tried to write some <em>javascript</em>, but as I've never done that before, I couldn't get far.</p>
  
  <p>The date from the first tab :</p>
  
  <pre><code>@*[...]*@    
  &lt;div class='form-group'&gt;
  &lt;div class="col-md-6"&gt;
      @Html.LabelFor(model =&gt; model.FirstImmatriculationDate)
  &lt;/div&gt;
  &lt;div class="col-md-6"&gt;
      &lt;div&gt;
          &lt;div class="input-group" style="width: 148px;"&gt;
              &lt;input class="form-control date-picker" type="text" data-date-format="dd/mm/yyyy" name="FirstImmatriculationDate" id="FirstImmatriculationDate" value="@Model.FormattedFirstImmat"&gt;
              &lt;span class="input-group-addon"&gt;
                  &lt;i class="fa fa-calendar"&gt;&lt;/i&gt;
              &lt;/span&gt;
              @Html.ValidationMessageFor(model =&gt; model.FirstImmatriculationDate, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;span id="error_msgFirstImmat" class="text-danger"&gt; @Resources.VehicleDetails_FirstImmatError&lt;/span&gt;
      &lt;span id="error_msgFirstImmatTooOld" class="text-danger"&gt; @Resources.VehicleDetails_FirstImmatTooOld&lt;/span&gt;
      &lt;span id="error_msgFirstImmatFormatDate" class="text-danger"&gt; @Resources.General_FormatDate&lt;/span&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  @*[...]*@
  </code></pre>
  
  <p>The DropDown on the second tab (on wich the data validation must be done) :</p>
  
  <pre><code>@*[...]*@
  &lt;div class='form-group'&gt;
  &lt;div class="col-md-6"&gt;
      @Html.LabelFor(model =&gt; model.Omnium_InnerNrDeductibleFormula)
  &lt;/div&gt;
  &lt;div class="col-md-6"&gt;
      @Html.DropDownListFor(model =&gt; model.Omnium_InnerNrDeductibleFormula, (SelectListItem[])ViewBag.lstFormulaDeduc, new { @id = "Omnium_InnerNrDeductibleFormulaId" })
      @Html.ValidationMessageFor(model =&gt; model.Omnium_InnerNrDeductibleFormula, "", new { @class = "text-danger" })
      &lt;span id="error_MisingFormula" class="text-danger"&gt;@Resources.Warranty_FormulaMissing&lt;/span&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  @*[...]*@
  </code></pre>
  
  <p>The code from the Forms view calling the two partial views</p>
  
  <pre><code>@*[...]*@
  &lt;div id="vehicleQuote" class="tab-pane in active"&gt;
  &lt;p&gt;@Html.EditorFor(model =&gt; model.VehicleDetails)&lt;/p&gt;
  &lt;a href="#" id="btnWarrantiesPage" class="btn  btn-group-lg" title="@Resources.Warranty_NextPage" style="margin-left:61%"&gt;
      &lt;i class="btn-label glyphicon glyphicon-arrow-right"&gt;&lt;/i&gt;
      @Resources.Warranty_NextPage
  &lt;/a&gt;
  &lt;/div&gt;
  &lt;div id="warrantyQuote" class="tab-pane"&gt;
      &lt;p&gt;@Html.EditorFor(model =&gt; model.Warranty)&lt;/p&gt;
  &lt;/div&gt;
  @{
      if (Model.ResultsModel != null)
      {
          if (Model.ResultsModel.RC != null || Model.ResultsModel.errorMsg != null)
          {
              &lt;div id="resultQuote" class="tab-pane in active"&gt;
                  &lt;p&gt;@Html.EditorFor(model =&gt; model.ResultsModel)&lt;/p&gt;
              &lt;/div&gt;
          }
      }
  }
  
  &lt;div id="submitQuote"&gt;
      &lt;div style="margin-left:61%"&gt;
  
          &lt;button type="submit" id="btnSave" name="BtnSave" class="btn btn-palegreen" value="@Resources.General_Save"&gt;
              &lt;i class="btn-label glyphicon glyphicon-saved"&gt;&lt;/i&gt;
              @Resources.General_Save
          &lt;/button&gt;
          &lt;button type="submit" id="btnTaskTarification" name="btnTaskTarification" class="btn btn" value="@Resources.General_Save"&gt;
              &lt;i class="btn-label glyphicon glyphicon-print"&gt;&lt;/i&gt;
              @Resources.General_Print
          &lt;/button&gt;
      &lt;/div&gt;
      &lt;a href="@Url.Action("Index", "Customers")" class="btn  btn-group-lg" title="@Resources.General_Cancel" style="margin-left:10px;"&gt;
          &lt;i class="btn-label glyphicon glyphicon-arrow-left"&gt;&lt;/i&gt;
          @Resources.General_Cancel
      &lt;/a&gt;
  &lt;/div&gt;
  @*[...]*@
  </code></pre>
  
  <p>The part of the model used for the DatePicker</p>
  
  <pre><code>public class VehicleDetails
  {        
      [Display(Name = "VehicleDetails_FirstImmatriculationDate", ResourceType = typeof(Resources.Resources))]
      public DateTime? FirstImmatriculationDate { get; set; }
      //[...]
  }
  </code></pre>
  
  <p>The part of the model used for the item selected in the DropDown</p>
  
  <pre><code>public class Warranty
  {
      [Display(Name = "Warranty_Omnium_InnerNrDeductibleFormula", ResourceType = typeof(Resources.Resources))]
      public string Omnium_InnerNrDeductibleFormula { get; set; }
      //[...]
  }
  </code></pre>