获取Json“500内部服务器错误”时遇到问题

时间:2013-02-14 05:33:34

标签: asp.net-mvc asp.net-mvc-3

以下是我的区域

enter image description here

控制器

public JsonResult Get_JSon()
{
    List<AdminModule> mod = new List<AdminModule>();
    mod.Add(new AdminModule { MyName = "1" });
    mod.Add(new AdminModule { MyName = "2" });
    mod.Add(new AdminModule { MyName = "3" });

    return Json(mod);
}

模型

public class AdminModule
{
    [Required]
    public String MyName { get; set; }
}

查看

@model _1.Areas.Admin.Models.AdminModule
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutPage1.cshtml";
}
<div id="formContainer_Json" style="display:none" 
      data-url="@Url.Action("Get_JSon", "Admin", new { area = "Admin" })">
</div>
<input id="BTN_Json" onclick="return GetJsonR()" type="button" value="Button" />
@section Scripts {
    <script type="text/javascript" 
             src="@Url.Content("~/areas/admin/scripts/myscript.js")"></script>
}

脚本

function GetJsonR() {
    var $formContainer = $('#formContainer_Json');
    var url = $formContainer.attr('data-url');
    $.get(url, null, function (data) { return false; });
    return false;
}

困惑是 - 提交按钮以获得Json结果 500内部服务器错误

同样在标题中显示以下信息......

<title>This request has been blocked because sensitive information could be 
disclosed to third party web sites when this is used in a GET request. To 
allow GET requests, set JsonRequestBehavior to AllowGet.</title>

1 个答案:

答案 0 :(得分:2)

替换以下行......

return Json(mod);

以下......

return Json(mod, JsonRequestBehavior.AllowGet);