小编Nai*_*aim的帖子

"参数字典包含参数的空条目" - 如何修复?

我正在尝试实现一个编辑页面,以便管理员修改数据库中的数据.不幸的是,我遇到了一个错误.

代码如下:

public ViewResult Edit(int productId) {
       // Do something here 
}
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

"The parameters dictionary contains a null entry for parameter 'productId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ViewResult Edit(Int32)' in 'WebUI.Controllers.AdminController'. To make a parameter optional its type should be either a reference type or a Nullable type.
Parameter name: parameters"
Run Code Online (Sandbox Code Playgroud)

我改变了我的路线Global.asax.cs:

 routes.MapRoute(
"Admin",
"Admin/{action}/{ productId}",
new { controller = "Admin", action = "Edit",  productId= "" }
);
Run Code Online (Sandbox Code Playgroud)

但我仍然得到错误.

c# asp.net asp.net-mvc

38
推荐指数
3
解决办法
7万
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

c# ×1