I want to use AJAX to recieve a JSON array from the controller. In php you can just return string instead of a view so you can do something like that:
$array = array(
"Hello" => "hi",
"Whatsup" => sup
);
return json_encode($array);
However, in C# you have to return ActionResult object. So until now I didn't find a good solution for "printing" the JSON array as the result.
You can return JsonResult instead of ActionResult to return your json:
public JsonResult MyAction()
{
//DoSomething
return Json(value);
}
Use JsonResult instead of ActionResult return type for your controller action method. Below mentioned path might help you: http://binodmahto.blogspot.in/2013/03/all-about-jsonobject.html
Also is right this code:
public ActionResult MyAction()
{
return Json(value);
}