i am wondering if it is possible to return multiple objects with a JSON result in MVC. At the moment i have no problem to return a single object.
public ActionResult AddToBasket(int quantity, int productdetailid)
{
// more code here
return Json ( new { Name = p.Product.Name, Price = p.Price});
}
This returns a single anonymous object in my ajax call.What i wanna do is return multiple Names and Prices to fill a table in my view.
So basicly i wanna update(renew) the cookie every time the user adds a item to his basket and update the basket which is a html table.
Thanks in advance.
Simply return an array of objects, e.g:
[ { Name: 'foo', Price: 123 }
, { Name: 'bar', Price: 456 }
, { Name: 'baz', Price: 789 } ]
Just return some enumerable if you want an array:
return Json ( Enumerable.Range(0, 10).Select(i => new { Name = "N" + i, Price = i });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With