Retrieve object array from FormCollection element in mvc 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', JSON.stringify(products));

Server code=================

using System.Web.Script.Serialization;

[HttpPost]
public ActionResult SalesData(FormCollection data)
{
String personId=data["PersonId"].ToString();
String submitDate=data["SubmitDate"].ToString();

var serializer = new JavaScriptSerializer();
    var productsStr = data["products"].ToString()
var deserializedProducts = serializer.Deserialize<List<Product>>(productsStr);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s