I serialize Fpr, and post it to the server using jquery.
in the action method, I try go get a List<T> or IEnumerable<T> of the object but the List<T> or IEnumerable<T> is null.
How to post it to the method so i will get it as List or IEnumerable.
var div = $("#TableForm").serialize();
$.post("../Controller/Action?Mode=" + Mode, div , function () { });
I serialize the form and the serialize is OK. The problem is only in the action – that i got null, please help
First of all, you can’t serialize a
tableobject:HTML:
JavaScript:
When the code pauses in the debugger, you can see that
serializedis"", the empty string. MVC won’t know how to model bind this to your IEnumerable, so it is null.On the other hand, if you do this:
Then
serializedwill be equal to"one=blah&two=moreblah".Second, if you’re actually binding to a
formthen all input elements inside the table will be correctly serialized. However, the names of your input elements are extremely important since you are trying to model-bind to anIEnumerable<CafePlaced>. Read this article by Phil Haack on model binding to a list: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspxIf you don’t do it correctly, then MVC won’t know how to model bind and your parameter will come through as null.