Can PHP array passed POST method to catch in ASP.NET MVC?
Query string: WebAccess/ArrayTest?val[]=1&val[]=2&val[]=3
I write: ActionResult ArrayTest (String[] val)
But this only works if the query string to remove the “[]”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The built in DefaultModelBinder in ASP.NET MVC can’t handle rails/php/jquery1.4 style array posts (which is what you’re referring to with val[]=1&val[]=2&val[]=3).
You have to either create a custom modelbinder (google it, lots of examples) or adding indices inside the bracket like so:
And the indices must not have any missing numbers.
I have fixed this with a script that on submit of the form just adds the indices. i.e. in jQuery: