[英]How to pass Json array from a controller to Javascript (ajax) in view.cshtml
我試圖將Document對象的數組從方法(比如說從控制器)傳遞到從中調用該方法的JavaScript(在視圖中)。 由於某種原因,該方法不會傳遞數組(僅當數組為空時才有效)。 我還嘗試將所有數組成員放入一個新數組,甚至是一個列表,並將其傳遞到視圖中,但是將無法正常工作(檢查元素->控制台= 500(內部服務器錯誤))( 此處為屏幕截圖 )。
這是JavaScript代碼的一部分:
$.ajax({
method:"get",
data: data,
url: url + "?binderId=" + companyId +"&description="+ data
}).success(function (response) {
console.log("Success");
console.log(response);
}).error(function (response) {
console.log("Error");
console.log(response);
});
這是C#代碼,從上面將數組發送到JavaScript:
public ActionResult SearchDocument(int binderId, string description)
{
//documents is a array
var documents = Search.SearchDocument(binderId, description);
return Json(documents, JsonRequestBehavior.AllowGet);
}
我認為JavaScript有點問題,但我不知道是什么。 謝謝!
嘗試返回JsonResult而不是ActionResult
公共JsonResult SearchDocument(int bindId,字符串描述)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.