我正在尝试实现一个编辑页面,以便管理员修改数据库中的数据.不幸的是,我遇到了一个错误.
代码如下:
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)
但我仍然得到错误.