Asp.net core MVC Session

 















public class MyController : Controller
{
  // Define an action method to handle the AJAX request
  [HttpPost] // or [HttpGet] depending on your configuration
  public ActionResult DropdownChanged(string selectedValue)
  {
    // Perform any necessary actions based on the selected value
    // and return the updated data or a JSON response.

    // Example logic:
    if (selectedValue == "option1")
    {
      // Do something when Option 1 is selected
    }
    else if (selectedValue == "option2")
    {
      // Do something when Option 2 is selected
    }
    else if (selectedValue == "option3")
    {
      // Do something when Option 3 is selected
    }

    // Return the updated data or a JSON response.
  }
}






<select id="myDropdown">
  <option value="option1">Option 1</option>
  <option value="option2">Option 2</option>
  <option value="option3">Option 3</option>
</select>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
  $(document).ready(function() {
    $('#myDropdown').change(function() {
      var selectedValue = $(this).val();
      // Make an AJAX request to the server with the selected value.
      $.ajax({
        url: '/ControllerName/DropdownChanged', // URL of the action method in the controller
        type: 'POST', // or 'GET' depending on your configuration
        data: { selectedValue: selectedValue },
        success: function(response) {
          // Handle the response from the server, such as updating the UI.
        },
        error: function(xhr, status, error) {
          // Handle any errors that occurred during the AJAX request.
        }
      });
    });
  });
</script>









Comments

Popular posts from this blog

₹2.5 Lakh ki Alkaline Machine: Investment Ya Hype?" Japan Technology Wale Alkaline Water Systems: Science Ya Sirf Marketing? "Alkaline Water Machines — Health Ke Naam Par Business?

How to Write "M Squared" (M²) in C#