参数字典在呈现局部视图时包含参数错误的空条目

The parameters dictionary contains a null entry for parameter error while rendering partial view

我基本上是在尝试刷新我对某些 clickEvent() 的部分视图,并且我正在为此执行 Ajax POST。我的视图如下所示:

<script type="text/javascript">
        $("#employeeGrid").click(function() {
            var grid = $("#employeeGrid").data("kendoGrid");
            var currentSelection = grid.dataItem(grid.select());
            alert(currentSelection.Id);
            $.ajax({
                data: JSON.stringify({ id: 1 }),
                url: "/Employee/ShowEmployeeDetails",
                type: "POST",
                success: function (result) {
                    // refreshes partial view
                    $('#EmployeeDetails').html(result);
                }
            });
        });
      </script>

我的控制器如下所示:

[HttpPost]
        public ActionResult ShowEmployeeDetails(int id)
        {

            List<EmployeeLOAHistory> employeeLoaHistoryList = new List<EmployeeLOAHistory>
            {
                new EmployeeLOAHistory
                {
                    Id = 1,
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now
                },
                new EmployeeLOAHistory
                {
                    Id = 2,
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now
                }
            };

此外,当我在 Firebug 中跟踪我的请求时,它还显示 id 已正确发布,看起来如下所示:

{"id":1}

然而,响应流讲述了完全不同的故事,它看起来像下面这样:

<title>The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult ShowEmployeeDetails(Int32)'

                return PartialView("_EmployeeDetails");
            }

我不知道为什么会这样。有什么建议吗?

您不需要对 json 对象进行字符串化。将 ajax 选项更改为

ajax({
    data: { id: 1 }, // change this
    url: '@Url.Action("ShowEmployeeDetails", "Employee")', // recommended
    .....