我想使用AJAX從控制器接收JSON數組。在PHP你可以只返回串代替視圖,所以你可以做這樣的事情:C#返回JSON而不是視圖(MVC)
$array = array(
"Hello" => "hi",
"Whatsup" => sup
);
return json_encode($array);
然而,在C#你有返回的ActionResult對象。因此,直到現在,我還是沒有找到一個好的解決方案來「打印」JSON陣列。
我想使用AJAX從控制器接收JSON數組。在PHP你可以只返回串代替視圖,所以你可以做這樣的事情:C#返回JSON而不是視圖(MVC)
$array = array(
"Hello" => "hi",
"Whatsup" => sup
);
return json_encode($array);
然而,在C#你有返回的ActionResult對象。因此,直到現在,我還是沒有找到一個好的解決方案來「打印」JSON陣列。
您可以返回代替的ActionResult JsonResult來回報您的JSON:
public JsonResult MyAction()
{
//DoSomething
return Json(value);
}
使用JsonResult而不是ActionResult返回類型爲您的控制器操作方法。下面提到的路徑可能會幫助您: http://binodmahto.blogspot.in/2013/03/all-about-jsonobject.html
而且是正確的驗證碼
public ActionResult MyAction()
{
return Json(value);
}
谷歌** ** JsonResult像http://chsakell.com/2013/06/08/retrieve-json-data-from-mvc-controllers-in-asp-net-mvc/ – gaurav 2014-10-31 09:15:25
使用'return Json(array);' – haim770 2014-10-31 09:19:11