Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 参数'的输入为空;id';_C#_Asp.net Mvc_Dictionary - Fatal编程技术网

C# 参数'的输入为空;id';

C# 参数'的输入为空;id';,c#,asp.net-mvc,dictionary,C#,Asp.net Mvc,Dictionary,所有类似的问题都解决了,但我找不到和我一样的错误 型号: public class CountriesViewModel { public int BuffId { get; set; } public string CountryId { get; set; } public string Name { get; set; } } 视图: @model List<BTGHRM.Models.CountriesViewModel> @{

所有类似的问题都解决了,但我找不到和我一样的错误

型号:

public class CountriesViewModel
{
    public int BuffId { get; set; }
    public string CountryId { get; set; }
    public string Name { get; set; }
}
视图:

    @model List<BTGHRM.Models.CountriesViewModel>
    @{ 
        WebGrid grid = new WebGrid(Model, canSort: false, rowsPerPage: 15);
        int row = 0;
    }


    @if (Model.Any())
    {

        @grid.GetHtml(
                tableStyle: "table",
                headerStyle: "table_HeaderStyle",
                footerStyle: "table_PagerStyle",
                rowStyle: "table_RowStyle",
                alternatingRowStyle: "table_AlternatingRowStyle",
                selectedRowStyle: "table_SelectedRowStyle",
                columns: grid.Columns(

                grid.Column("Name", @Resources.Localization.country, format: @<text>
                        <span class="display-mode"><label id="NameLabel">@item.Name</label></span>
                        @Html.TextBox("Model[" + (++row - 1).ToString() + "].Name", (object)item.Name, new { @class = "edit-mode" })
                </text>, style: "p40"),

                      grid.Column("", "", format: @<text>
                        @Html.Hidden("Model[" + (row - 1).ToString() + "].BuffId", (object)item.BuffId, new { @class = "edit-mode" })
                    </text>, style: "p13"),

            grid.Column("", "", format: @<text>
                        <a href="DeleteCountryRecord/@item.BuffId" id="@item.BuffId" class="link_button delete-button display-mode">@Resources.Localization.delete</a>
            </text>)
                )
            )
    }
我所有的身份证都是对的,但我搞错了

参数字典包含“BTGHRM.Controllers.AdministrationController”中“System.Web.Mvc.ActionResult DeleteCountryRecord(Int32)”方法的不可为空类型“System.Int32”的参数“BuffId”的空条目。可选参数必须是引用类型、可为null的类型或声明为可选参数。 参数名称:参数

但在点击按钮后生成的链接中可以看到,该id发布在右侧:


我的问题是什么?

您必须确保定义的路由专门命名为
BuffId
。也可以在操作方法签名中将参数重命名为
id
,假设默认值在路由表中

如果添加新路由,它将与其余路由(可能是RouteConfig.cs)一起,并确保其高于默认路由:

routes.MapRoute(
    name: "DeleteCountryRecord",
    url: "Administration/DeleteCountryRecord/{BuffId}",
    defaults: new { controller = "Administration", action = "DeleteCountryRecord" }
);

您必须确保定义的路由专门命名为
BuffId
。也可以在操作方法签名中将参数重命名为
id
,假设默认值在路由表中

如果添加新路由,它将与其余路由(可能是RouteConfig.cs)一起,并确保其高于默认路由:

routes.MapRoute(
    name: "DeleteCountryRecord",
    url: "Administration/DeleteCountryRecord/{BuffId}",
    defaults: new { controller = "Administration", action = "DeleteCountryRecord" }
);