0

I found the following code at: Send POST data on redirect with JavaScript/jQuery?

$.extend(
    {
        redirectPost: function (location, args) {
            var form = $('<form></form>');
            form.attr("method", "post");
            form.attr("action", location);

            $.each(args, function (key, value) {
                var field = $('<input></input>');

                //Change the following back to hidden 
                field.attr("type", "hidden");
                //field.attr("type", "text");
                field.attr("name", key);
                field.attr("value", value);

                form.append(field);
            });
            $(form).appendTo('body').submit();
        }
    });

I call this redirect from jquery with the following:

var redirect = 'ListDatabaseDetails.cshtml?id=999999';
$.redirectPost(redirect, { 'ServerID': '1', 'DBID': '23' });

Can this be done with a .cshrml target page? If so, how do I retrieve the two values: ServerID and DBID on the target page?

I have tried the following JavaScript on the target .cshtml page with no success-the fields aren't there:

function load_data() {
    var ServerID = document.getElementById("ServerID").value;
    var DBID    = document.getElementById("DBID").value;
}

Thanks for any help.

Ele
  • 31,191
  • 6
  • 31
  • 67
StevenJe
  • 74
  • 1
  • 11
  • The question should be: Can this be done with a .cshtml target page? If so, how do I retrieve the two values: ServerID and DBID on the target page? – StevenJe Jan 11 '18 at 00:57

1 Answers1

0

I was able to figure this out using c# razor code, with the values posted in from jquery in the sending page. In the target .cshtml page, I added:

@{
var serverID = Request["ServerID"];
var dbID = Request["DBID"];
}

This stored the values in the serverID and dbID variables which were populated with the data from the sending page. yay!

StevenJe
  • 74
  • 1
  • 11