Returning json from northwind db with asp.net mvc4

mrbachkhoa

New Member
i'm trying to return a json object from my controller to my view. i'm using the the northwind db for testing and used used dbfirst for creating the model. from what i understand i have to use anonymous types for json. however it doesn't work. and i don't what's the best approach to debuging.(with the manualy generated list i commented out it works...)Controller:\[code\]public JsonResult GetData() { ////List<int> result = new List<int>() { 1, 4, 5 }; ////return Json(result); using (var db = new NorthwindEntities()) { var results = from Cust in db.Customers select new { CustomerAddress = Cust.Address, CustomerCity = Cust.City, CustomerCompanyName = Cust.CompanyName }; return Json(results); Console.Write(results); } }\[/code\]View:\[code\]<input id="btn" type="button" /><script type="text/javascript">$("#btn").click(function () { $.post("/Northwind/GetData", null, function (data) { alert(data); });});</script>\[/code\]
 
Back
Top