title: MVC - passing js variable to controller through ajax then using it in view
body: <p><strong>script:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(function () {
      $('#datetimepicker').datetimepicker({
          disabledDates: [
              new Date()
          ],
          inline: true,
          format: 'L',
          daysOfWeekDisabled: [0, 6],
          minDate: new Date(),
          useCurrent: false
      });
  
      $('#datetimepicker').on('change.datetimepicker', function (event) {
          var formatted_date = event.date.format('M/DD/YYYY');
          $('#datetimepickerOut').val(formatted_date);
  
          $.ajax({
              url: '@Url.Action("Create")',
              contentType: 'application/html; charset=utf-8',
              data: { calendarDate: formatted_date },
              success: function (data) {
                  $('#divTimeSlots').fadeIn("slow");
              },
              failure: function (result) {
                  alert(errMsg);
              }
          });
  
      });
  
      $('#divTimeSlots input').on('change', function (event) {
          $('#SlotTimeOut').val($("[type='radio']:checked").val());
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>controller:</strong></p>
  
  <pre><code>public ActionResult Create(string calendarDate)
  {
      testViewModel mvm = new testViewModel();
  
      mvm.myDate = calendarDate;
  }
  </code></pre>
  
  <p><strong>Create view:</strong></p>
  
  <pre><code>&lt;div class="col-md-5" id="divTimeSlots" style="display: none;"&gt;
  @{
      var getDate = Model.myDate;
  
      foreach (var rTimeSlots in Model.ListSlotTimeForRadio.Where(n =&gt;
          n.BranchCode == "MNL1" &amp;&amp;
          n.Slots &gt; 0
          &amp;&amp;
          n.SlotCode == getDate
          ))
      {
          @Html.RadioButtonFor(model =&gt; model.ListSlotTimeForRadio, rTimeSlots.SlotTime,
          new { htmlAttributes =
              new Dictionary&lt;string, object&gt;
              {
                  { "id", "timeSlots" },
                  { "class", "form-control" }
              }
          })
  
          @rTimeSlots.SlotTime&lt;br&gt;
      }
  }
  &lt;/div&gt;
  </code></pre>
  
  <p>as you can see in my script, that is inline datepicker. when i click on any date in the timepicker, the value will be pass on the variable formatted_date. formatted_date will also be pass on to controller through ajax (see calendarDate). then then calendarDate is passed to model as myDate (see controller). clicking on any date, the radiobutton will appear base on the foreach and .fadein("slow") in script. but, when i add the &amp;&amp; n.SlotCode == getDate in foreach, the radiobutton list is not appearing. getDate is myDate.</p>
  
  <p>when i use &amp;&amp; n.SlotCode == "2/22/2019", that is working, radiobutton list is showing. but when i use == getDate, it doesn't work. </p>
  
  <p><a href="https://i.stack.imgur.com/3rBy1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3rBy1.png" alt="debugged controller"></a>
  <a href="https://i.stack.imgur.com/ehOu2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ehOu2.png" alt="debugged view"></a></p>
  
  <p>as i'm debugging it, i'm getting the date correctly. but the radiobutton list is not appearing, i placed it in the success function. but it seems that it is not working correctly.</p>
  
  <p>i don't know what's wrong. please help. tia</p>