The parameters dictionary contains a null entry for parameter 'id' of non-nullable...
[已解决] The parameters dictionary contains a null entry for parameter 'id' of non-nullable...
当前页面:http://www.senparc.com/SZD-27
{ 收藏当前页面 }
20
[Web开发 > ASP.NET > ASP.NET MVC]
ASP.NET MVC2中,URL如下:
http://localhost:14639/Admin/UpdateAdvItem?id=9ec32a5b-d6ed-4cb9-9ca2-68eb0bc8ed76
Action中接受的id也是Guid类型,但是报错:
The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Guid'
谁知道这是怎么回事?
http://localhost:14639/Admin/UpdateAdvItem?id=9ec32a5b-d6ed-4cb9-9ca2-68eb0bc8ed76
Action中接受的id也是Guid类型,但是报错:
The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Guid'
谁知道这是怎么回事?
最佳答案
原因是,MVC的Routing一旦设置了:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
这样的格式之后,id参数就只能从这个格式的url中获取,当你后面再加?id=xxx的时候,就会被忽略。
所以只需要把Url调整为:http://localhost:14639/Admin/UpdateAdvItem/9ec32a5b-d6ed-4cb9-9ca2-68eb0bc8ed76
这样的格式就可以了。
这个应该算是一个bug。
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
这样的格式之后,id参数就只能从这个格式的url中获取,当你后面再加?id=xxx的时候,就会被忽略。
所以只需要把Url调整为:http://localhost:14639/Admin/UpdateAdvItem/9ec32a5b-d6ed-4cb9-9ca2-68eb0bc8ed76
这样的格式就可以了。
这个应该算是一个bug。
回答时间:2010/3/12 20:57:13
| 回答者:jeffreysu
其他参考答案(0)
提交失败!请检查错误!错误信息:
以下信息或许对您有用:
- [已解决] 20 ASP.NET MVC 3.0自定义ViewEngine后出现错误:must d... 2012/8/25 22:02:58
- [已解决] 100 ASP.NET MVC 3 RC2下载地址?有说明文档的话更好!谢谢! 2010/12/12 12:23:00
- [已解决] 20 The type 'System.Data.Objects.DataClasse... 2010/11/25 16:51:58
- [已解决] 20 ASP.NET MVC 3 RC中的Razor语法,在VS中已经实现了智能感知和... 2010/11/14 15:51:22
- [已解决] 60 ASP.NET MVC Razor 在VS2010中智能感知的插件哪里有下载? 2010/11/3 12:53:18