title: What to do if Optional Parameter concept doesn't work?
body: <p>I have a JS function which takes a value from a textbox based on the Radio button selected.</p>
  
  <p>Example: If RadioButton <strong>No</strong> is Selected, values is teken from <strong>TextBox A</strong>, else if RadioButton <strong>Yes</strong> is selected, Value is taken from <strong>TextBox B</strong>. The following script is in my view</p>
  
  <pre><code>$('#btnVolunteerSaveBtn').on('click', function() { // on click of save button
    if (document.getElementById('RadioNo').checked) { //ID of radio button NO
      var checking = $('#Donation').val(); //ID of textbox from where the value is to be taken if RadioButton No is selected
      if (checking == "") {
        //if nothing is entered, stop from saving in DB
      } else {
        x = $('#Donation').val(); //ID of textbox from where the value is to be taken if RadioButton No is selected
        $.ajax({
          url: '@Url.Action("DonationValue","VolunteerInfo")',
          data: {
            name: x
          },
          type: "POST"
        });
      }
    } else {
      x = $('#GetNames').val(); //ID of textbox from where the value is to be taken if RadioButton Yes is selected
      $.ajax({
        url: '@Url.Action("DonationValue","VolunteerInfo")',
        data: {
          name: x
        },
        type: "POST"
      });
    }
  });
  </code></pre>
  
  <p>Till here it seems to work fine. Now coming to the controller, I have a function <code>DonationValue</code></p>
  
  <p><strong>My Question:</strong></p>
  
  <ol>
  <li>How can I pass the <code>name</code> parameter above?</li>
  <li>If nothing is filled in TextBox with id #Donation, how do I stop
  from saving the form in the DB?</li>
  </ol>
  
  <p><strong>My Attempt:</strong></p>
  
  <p>I tried doing </p>
  
  <pre><code>public string DonationValue(string name = null)
  {
      return name; //Trying to pass this value above
  }
  </code></pre>
  
  <p>This didn't help. It resolved the error but the passed value was always null. I also tried a couple of other things but none helped.</p>
  
  <p><strong>Edited:</strong></p>
  
  <pre><code>[HttpPost]
  public ActionResult AddVolunteer(VolunteerInfo viewModel)
  {
      if (!ModelState.IsValid)
      {
          return View("AddVolunteer", viewModel);
      }
  
      var volunteer = new VolunteerInfo()
      {
          Name = viewModel.Name,
          BirthdayDateTime = viewModel.BirthdayDateTime,
          Address = viewModel.Address,
          PhoneNumber = viewModel.PhoneNumber,
          EmailAddress = viewModel.EmailAddress,
          OccasionsID = viewModel.OccasionsID,
          DonationForWhom = _DonationValue
      };
  
      if (!string.IsNullOrEmpty(volunteer.DonationForWhom))
      {
          _context.VolunteerInfos.Add(volunteer);
          _context.SaveChanges();
          return RedirectToAction("Index", "Home");
      }
  
      return //something to save state so that user doesnt have to enter all the values again
  }
  
  [HttpPost]
  public void DonationValue(string name)
  {
      _DonationValue = name;
  }
  </code></pre>