'Button Click to return to the same page with same input parameters

I want users to navigate back to the same page after the button is clicked on the page. If the user URL is https://localhost:xxx/Inventories/Index/38?custID=38&rmName=A2A click on the button should do the processing and come back to the same page with same input parameter. On the button click I have the below logic

<script type="text/javascript">
    $(document).ready(function () {
        $(document).on("click", "#buyNow", (function (e) {
            e.preventDefault();
            e.stopImmediatePropagation();
                var id=$(this).data("id");
            onBuyNow(id);
        }));

        function onBuyNow(id) {
           
            var quantityReq = $("#quantityReq" + id).val();
            var customerId = $("#customer" + id).val();
            var data = {
                customerID: customerId,
                quantityReq: quantityReq,
                invetoryID: id
            };

            $.ajax({
                type: 'POST',
                url: '@Url.Action("OrderItem", "Inventories")',
                data: data,
                dataType: "json",
                success: function (result) {
                    alert("hello");
                    var url = '@Url.Action("Index", "Inventories")';
                    var rmName = @HttpContextAccessor.HttpContext.Request.Query["rmName"];
                    alert(roomId);
                    window.location.href = `${url}?custID=${customerId}&rmName=${rmName}&success=true`;
                },
                error: function (error) {
                    alert(error);
                }
            });
            };
        });
</script>

When I click on the button after the button does the processing I can see the alert with hello but when it tries to get the query parameter from the current page @HttpContextAccessor.HttpContext.Request.Query["rmName"]; it keeps throwing

enter image description here

Is there suggestion how I can go back to the existing page after the button click is successful. Any help is greatly appreciated



Solution 1:[1]

Like where should I add the quotes?

As @GuyVdN said, you should modify the rmName to a string instead of being the object.

You should put it like this and then it will work.

                var rmName = '@HttpContextAccessor.HttpContext.Request.Query["rmName"]';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brando Zhang