Posting a list of objects trough json to actionMethod in asp.net mvc
Seems there have been some talk about this issue before, but i will post this anyway..
Public Function test(ByVal val As List(Of TestObj)) As ActionResult
For Each o In val
Next
End Function
Class TestObj
Property id As Integer
Property name As String
End Class
When trying to call this function trough jQuery's post method the mvc framework is not able开发者_JAVA技巧 to convert my json into the val paremeter. If i do a dump of my request it looks like this..
?Request.Form("val")
"[{"id":1,"name":"dsfdf"},{"id":2,"name":"dsfdf"},{"id":3,"name":"dsfdf"}]"
and the value of val is a list, but the json string is noth converted into the objects, so the count of the list is 0.
I have seen some solutions for this, implementing and using attributes, but ... I have done this several times in the context of .asmx webservices and it works out of the box, so I hoped this would work like a charm in mvc as well.. :) Is there something that I have missed or is the attribute approch the only way to do it?
精彩评论