c# - Retrieve object array from FormCollection element in mvc controller -
i'm trying send data html page mvc controller. it's sent formdata via ajax, , handled in controller formcollection. 1 of element array of object. how can retrieve array in controller?
client code================ var products = [] $('tr').each(function () { var row = $(this); var product = {}; product.id = row.find('.id').val(); product.id = row.find('.quantity').val(); products.push(product); }); var data = new formdata(); data.append('personid', pid); data.append('submitdate', sdate); data.append('products', products); server code================= [httppost] public actionresult salesdata(formcollection data) { string personid=data["personid"].tostring(); string submitdate=data["submitdate"].tostring(); //how retrieve products ?? }
any help?
thank you.
try strigify products , deserialize on server.
data.append('products', json.stringify(products));
on server (assume product class id, value) using javascriptserializer
var serializer = new javascriptserializer(); var productsstr = data["products"].tostring() var deserializedproducts = serializer.deserialize<list<product>>(productsstr);
Comments
Post a Comment