Thursday, November 8, 2012

old school JsonResult stuff

This suggests doing it like this:

public JsonResult GetCityList()
{
   var list = from city in repository.Cities.GetAll()
      select new { Text = city.Name, Value = city.ID };
   return Json(list.ToList());
}

 
 

I've done it like this before:

public ActionResult Whatever()
{
   return Json(new { greeting = "hello" }, JsonRequestBehavior.AllowGet);
}

 
 

JsonRequestBehavior is of the System.Web.Mvc namespace.

No comments:

Post a Comment