// AJAX: Called by the JqGrid control public ActionResult Grid(JqGridSearchCriteria criteria) { var draftJson = new { total = 1, page = 1, records = 1, rows = new[] { new{ id = 8, cell = new[] { "data1", "data2", "9/13/2010", } } }, }; return Json(draftJson, JsonRequestBehavior.AllowGet); }
How to return Json data from MVC controller
September 15, 2011
iOS c#, controller, json, mvc 5 Comments
Sep 16, 2011 @ 03:13:22
I liked the idea that Oren Eini has implemented – you have your abstract controller to remove all cross-cutting concerns. Among those is also an overload for Json method that only takes the object (w/o JsonRequestBehavior). That way it looks clean and simple: return Json(new….);
Sep 17, 2011 @ 20:41:51
I like the idea. That sounds good Sean.
Sep 22, 2011 @ 15:43:07
Note to self – syntax for name/value pair:
var result = new { Status = “Success”, PaymentDueDate = paymentDueDateFormatted };
Feb 17, 2012 @ 10:15:49
Hi
public ActionResult About()
{
List listStores = new List();
listStores = this.GetResults(“param”);
return Json(listStores, “Stores”, JsonRequestBehavior.AllowGet);
}
Using the above code i am able to get the below result :
[{“id”:”1″,”name”:”Store1″,”cust_name”:”custname1″,”telephone”:”1233455555″,”email”:”abc@ac.com”,”geo”:{“latitude”:”12.9876″,”longitude”:”122.376237″}},{“id”:”2″,”name”:”Store2″,”cust_name”:”custname2″,”telephone”:”1556454″,”email”:”nfnf@ac.com”,”geo”:{“latitude”:”12.9876″,”longitude”:”122.376237″}},
how would i able to get the result in below format ? would need stores at the beginning of the result.
{
“stores” : [
{“id”:”1″,”name”:”Store1″,”cust_name”:”custname1″,”telephone”:”1233455555″,”email”:”abc@ac.com”,
“geo”:{“latitude”:”12.9876″,”longitude”:”122.376237″}},{“id”:”2″,”name”:”Store2″,”cust_name”:”custname2″,”telephone”:”1556454″,”email”:”nfnf@ac.com”,”geo”:{“latitude”:”12.9876″,”longitude”:”122.376237″}} ] }
Please help me in this regard.
Feb 28, 2012 @ 23:25:26
@Mahesh:
No compiler here to test with, but does this solve your problem?
public ActionResult About()
{
var jsonVal = new {
stores = this.GetResults(“param”)
}
return Json(jsonVal, JsonRequestBehavior.AllowGet);
}