参数字典包含方法的不可为空类型 'System.Int32' 的参数 'id' 的空条目

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method

当我尝试 post 通过操作 link 时出现此错误。我有一个默认的地图路线。

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Rent_Approval(Kendo.Mvc.UI.DataSourceRequest, Int32)' in .....

这是我的操作link

@Html.ActionLink("Send For Approval","Rent_Approval", "RentRequisition", new { id = "#=RentID#" }, new { @onclick = "OnIndexCall(this)" })

这是我的操作方法

    public ActionResult Rent_Approval([DataSourceRequest] DataSourceRequest request, int id)
    {
        var record = db.RentRequisitions.FirstOrDefault(p => p.RentID == id);
        try
        {
            if (record != null)
            {
                record.Status = Enum.GetName(typeof(OperationStatuses), 4);
                db.Requisitions.Attach(record);
                db.Entry(record).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            var model = new List<RentRequisition> { record };

            return RedirectToAction("Index");
        }

我觉得 link 的语法不正确。 引用您的视图模型以获取 link 的参数

中的参数值

尝试...

@Html.ActionLink("Send For Approval","Rent_Approval", "RentRequisition", new { id = Model.RentID}, new { @onclick = "OnIndexCall(this)" })

希望对您有所帮助