Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have this code working, it prints all email adresses it gets from a request to gmail
but now I need to send the array with results to another partial view
how can I store it in a way that I can use it somewhere else? (the partialview does appear on the same page)

C#
var array = response.contacts.asArray();
               var html = "You have " + array.length + "contacts<BR/>";
               html += "<table cellpadding=20>";
               for (var i = 0; i < array.length ; i++) {
                   html += "<tr><td align=center valign='bottom'>";
                   html += array[i].email + "</td></tr>";
               }
               html += "</table>";
               document.getElementById('contacts').innerHTML = html;
           } else {
               alert('Error :' + response.errorMessage);
           }


thanks a lot!
Posted
Comments
Sergey Alexandrovich Kryukov 14-May-13 14:50pm    
The answer is: Ajax.
—SA
Sam Van den Bossche 15-May-13 3:14am    
I know but how ^_^
Sergey Alexandrovich Kryukov 15-May-13 10:46am    
It looks like you do know...
—SA
Sam Van den Bossche 15-May-13 3:33am    
I now have
$.ajax({
url: '@Url.Action("MailListArray", "Mail")',
data: {mailList: array},
type: 'POST',
dataType: "json"
});

you can use JSON to represent your array, or any other object for that matter. Convert the array you have to a JSON string, then send the string to anywhere you want and on the receiving end recreate the array from the JSON string.

The code will look something like this
JavaScript
//sender
var data= JSON.stringify(MyObject);
Send(data);

//receiver
MyObject = JSON.parse(data);

http://www.json.org/[^]
 
Share this answer
 
var mailList = { mailList: mailListArray };

                $.ajax({
                    type: "POST",
                    url: '@Url.Action("MailListArray", "mail")',
                    data: mailList,
                    success: function (data) {
                        alert(data.Result);
                    },
                    dataType: "json",
                    traditional: true
                });

this is a call to a mvc controller.
traditional: true

this was the key to succes!
thanks to;
http://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form[^]

thanks y'all
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900