Home Post multiple data items through redirectPost() function to .cshtml page
Reply: 1

Post multiple data items through redirectPost() function to .cshtml page

StevenJe
1#
StevenJe Published in 2018-01-11 00:55:55Z

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.

StevenJe
2#
StevenJe Reply to 2018-01-11 04:21:20Z

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!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.317812 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO