2

I'm trying to send some data from html page to mvc controller. It's sent as FormData via ajax, and handled in controller as FormCollection. One of the element is an array of object. How can i retrieve this 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 to retrieve Products ??
 }

Any help?

Thank you.

1
  • @Ehsan, this is fully unknown to me. If you have any idea how to do it, please share. I think you don't know it.
    – s.k.paul
    Commented Aug 18, 2014 at 9:53

1 Answer 1

5

Try to strigify the products and deserialize on server.

data.append('Products', JSON.stringify(products));

on Server (Assume product class with id, value) using JavaScriptSerializer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.