on change sent value to controller check data and reload them RRS feed

  • Question

  • User1051638994 posted

    Hello I am tying to pass the value of a dropdown to controller. Based on that value I need to do some checks with if statement and then to reload data in my table.

    Here is what I have done so far


            $(document).ready(function () {
                $("#Records").on("change", function () {
                    var records = $("#Records").val();
                        url: '/Records/AllRecords',
                        type: "POST",
                        dataType: "JSON",
                        data: { records: records },
                        success: function () {
    // what I need here...a reload perhaps? } }) }); }); </script>

    Friday, November 13, 2020 6:30 AM

All replies

  • User475983607 posted

    I recommend a standard HTTP GET rather than a post.

        $("#Records").on("change", function () {
            window.location = '/Records/AllRecords?records=' + $("#Records").val();

    Or the following if this is an MVC app with standard routing.

    $("#Records").on("change", function () {
        window.location = '/Records/AllRecords/' + $("#Records").val();


    Friday, November 13, 2020 12:59 PM
  • User-474980206 posted

    If the result of the Ajax call is to navigate to a new page, why use Ajax? Just do a form post, and have the action return the correct html. Save a request. 

    Friday, November 13, 2020 3:22 PM