Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a List<int> via FormUrlEncodedContent

On the requester side my code looks like following

var myList = new List<int> {1,2,3};

var content = 
    new FormUrlEncodedContent
    (
        new KeyValuePair<string, string>[]
        {
        KeyValuePair.Create("myList", myList.ToString())
        }
    );

//Make Post Request here

On the receiver end I want my controller method to be

[HttpPost]
public void MyMethod(List<int> myList)
{
    \\ Doing stuff here
}

like image 330
KnightFox Avatar asked Oct 18 '25 13:10

KnightFox


1 Answers

You can try to do:

var myList = new List<int> { 1, 2, 3 };

var myPostData = new KeyValuePair<string, string>[]
{
    new KeyValuePair<string, string>("myList", string.Join(",", myList))
};

var content = new FormUrlEncodedContent(myPostData);
like image 66
Dmitry Zaets Avatar answered Oct 21 '25 03:10

Dmitry Zaets



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!