Marius Vasile

Marius Vasile

  • 1.2k
  • 932
  • 18.5k

jquery redirect to page

Jun 14 2021 5:21 PM

Momentarily I manage to redirect to another page with parameter using

<form id="Form1" asp-page-handler="Form1Post" asp-route-id="1" method="post"></form>
<form id="Form2" asp-page-handler="Form2Post" asp-route-id="2" method="post"></form>
<form id="Form3" asp-page-handler="Form3Post" asp-route-id="3" method="post"></form>

and

public IActionResult OnPostForm1Post()
        {
            return RedirectToPage("/Test");
        }
        public IActionResult OnPostForm2Post()
        {
            return RedirectToPage("/Index");
        }
        public IActionResult OnPostForm3Post()
        {
            return RedirectToPage("/IndexMain");
        }

and

$(function () {
            $("#RepType").on("change", function () {
                var data = $("#RepType :selected").text();
                if (data == "Unsafe Act") {
                    $('#Form1').submit();
                }
                else if (data == "Unsafe Condition") {
                    $('#Form2').submit();
                }
                else if (data == "Near-Miss") {
                    $('#Form3').submit();
                }
            });
        });

How can I do it directly from jquery?


Answers (6)