简体   繁体   English

参数字典包含非空类型'System.Int32'的参数'id'的空条目

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

I keep getting this error passed to me when I submit an edit. 提交修改后,我一直将此错误传递给我。 I've tried a few different tactics like adding int? 我尝试了几种不同的策略,例如添加int? or sending the id's through the url, but I can't figure out what I'm doing wrong. 或通过网址发送ID,但我无法弄清楚自己做错了什么。

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32, Int32)' in 'XXX.Controllers.OBProfileTaskFieldsController'. 参数字典在'XXX.Controllers.OBProfileTaskFieldsController'中的方法'System.Web.Mvc.ActionResult Index(Int32,Int32)'中包含非空类型'System.Int32'的参数'id'的空条目。 An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. 可选参数必须是引用类型,可为空的类型,或者必须声明为可选参数。

Parameter name: parameters 参数名称:参数

I have my controller that looks like this: 我的控制器如下所示:

[HttpPost]
    public ActionResult Edit(int id, int tid, OBProfileTaskFields fieldToUpdate)
    {
        try
        {
            OBProfileTaskFields originalField = this.dbContext.OBProfileTaskFields.FirstOrDefault(obptf => obptf.ProfileID == fieldToUpdate.ProfileID && obptf.TaskID == fieldToUpdate.TaskID && obptf.FName == fieldToUpdate.FName);
            originalField.FRequired = fieldToUpdate.FRequired;
            originalField.FLocked = fieldToUpdate.FLocked;
            originalField.CCAccess = fieldToUpdate.CCAccess;
            originalField.EEAccess = fieldToUpdate.EEAccess;
            if (originalField.SeqNbr != fieldToUpdate.SeqNbr) ReorderProfileTaskFields(fieldToUpdate.ProfileID, fieldToUpdate.TaskID, fieldToUpdate.FName, (int)fieldToUpdate.SeqNbr);
            originalField.SeqNbr = fieldToUpdate.SeqNbr;
            this.dbContext.SaveChanges();
            return RedirectToAction("Index", "OBProfileTasks", new { id = originalField.ProfileID});
        }
        catch
        {
            return View(this.dbContext.OBProfileTaskFields.FirstOrDefault(obptf => obptf.ProfileID == fieldToUpdate.ProfileID && obptf.TaskID == fieldToUpdate.TaskID && obptf.FName == fieldToUpdate.FName));
        }
    }

and my view is like this: 我的看法是这样的:

<!--Modals-->
                    <div class="modal fade" id="instructions-@item.TaskID" tabindex="-1" role="dialog" aria-labelledby="instructionsLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="instructionsLabel">Instructions</h4>
                                </div>
                                @using (Html.BeginForm("Edit", "OBProfileTaskFields", FormMethod.Post))
                                {
                                    <div class="modal-body">
                                        <input type="hidden" name="id" value="@item.ProfileID"/>
                                        <input type="hidden" name="tid" value="@item.TaskID" />
                                        <p>Placeholder text for isntructions or anything of that sort.</p>
                                        @Html.TextAreaFor(modelItem => item.CCInstruction, new {@class = "form-control", @rows = "6", @style = "width: 80%;"})
                                        <p>Placeholder text for isntructions or anything of that sort.</p>
                                        @Html.TextAreaFor(modelItem => item.EEInstruction, new {@class = "form-control", @rows = "6", @style = "width: 80%;"})
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        <button type="submit" class="btn btn-primary">Save changes</button>
                                    </div>
                                }

                            </div>
                        </div>
                    </div>

I am passing the two different IDs that i assume I need. 我正在传递我认为需要的两个不同的ID。

You've got the error here: return RedirectToAction("Index", "OBProfileTasks", new { id = originalField.ProfileID}); 您在这里遇到了错误: return RedirectToAction("Index", "OBProfileTasks", new { id = originalField.ProfileID}); You pass only 1 parameter while the error says that Index requires 2 ( Index(Int32, Int32) ) 您仅传递1个参数,而错误表明Index需要2个参数( Index(Int32, Int32)

Here it's seems that the method Index required 2 parameters so you have to redirect with 2 paramters like` 看来方法Index需要2个参数,因此您必须使用2个参数进行重定向,例如`

  return RedirectToAction("Index", "OBProfileTasks", new { id = originalField.ProfileID, tid = 2});

Here we i choose tid= 2 在这里我选择tid = 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数字典包含不可为空类型“System.Int32”的参数“id”的 null 条目。 - The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' . . 参数字典包含非空类型&#39;System.Int32&#39;的参数&#39;_id&#39;的空条目 - The parameters dictionary contains a null entry for parameter '_id' of non-nullable type 'System.Int32' 参数字典包含一个 null 条目,用于不可为空类型“System.Int32”的参数“id” - The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' Create(Int32) 参数字典包含不可为空类型“System.Int32”的参数“id”的空条目 - Create(Int32) the parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' 参数字典包含非空类型为&#39;System.Int32&#39;的参数的空条目 - The parameters dictionary contains a null entry for parameter of non-nullable type 'System.Int32' 参数字典包含非空类型&#39;System.Int32&#39;的参数&#39;SolutionArchitectID&#39;的空条目 - The parameters dictionary contains a null entry for parameter 'SolutionArchitectID' of non-nullable type 'System.Int32' 参数字典包含非空类型“ System.Int32”的参数“ imageWidth”的空条目 - The parameters dictionary contains a null entry for parameter 'imageWidth' of non-nullable type 'System.Int32' 参数字典包含用于方法的非空类型&#39;System.Int32&#39;的参数&#39;userId&#39;的空条目 - The parameters dictionary contains a null entry for parameter 'userId' of non-nullable type 'System.Int32' for method 参数字典包含非可空类型&#39;System.Int32&#39;的参数&#39;testId&#39;的空条目 - The parameters dictionary contains a null entry for parameter 'testId' of non-nullable type 'System.Int32' 参数字典包含用于方法的非空类型&#39;System.Int32&#39;的参数&#39;foo&#39;的空条目 - The parameters dictionary contains a null entry for parameter 'foo' of non-nullable type 'System.Int32' for method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM