I get model’s values from view with this codeblock and this part is OK.
var data = new FormData();
var datas = $(this).serializeArray();
for (var i = 0; i < datas.length; i++) {
data.append(datas[i].name, datas[i].value);
}
In addition I want to add a list to data variable with this code block.
commentlist.push({ CommentID: commentguid, UserName: username, Comment: comment, MainCommentID: topcommentid });
data.append("Comments", commentlist);
And this is the list in my model from controller side.
public List<CommentModalClass> Comments { get; set; }
In summary I want to send commentlist
to controllerside in data
but I couldn’t make it.
2
Answers
For passing the array of objects in
FormData
, the properties should be as below:Thus it should be looked like:
Serialize the comments data in Jquery and send using Ajax call. For server side function definition should received a string and within that action method deserialize the data into your view model comments property i.e.
In JavaSript file:
In Your Code file: