customers is a List<string>.
RedirectToAction("ListCustomers", new { customers = customers });
And when I send the list it contains 4 items, but when I receive it in my controller method it has only one item and it’s of type generic list. That seems not be what I want. But how to pass more complex data than strings and integer between controller methods?
You cannot send complex objects when redirecting. When redirecting you are sending a GET request to the target action. When sending a GET request you need to send all information as query string parameters. And this works only with simple scalar properties.
So one way is to persist the instance somewhere on the server before redirecting (in a database for example) and then pass only an id as query string parameter to the target action which will be able to retrieve the object from where it was stored:
and inside the target action:
Another possibility is to pass all the values as query string parameters (be careful there’s a limit in the length of a query string which will vary among browsers):
Yet another possibility is to use TempData (not recommended):
and then: