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...

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'

谁知道这是怎么回事?
提问时间:2010/3/12 20:52:48 | 提问者:GaLiJiKuai | 悬赏:20 | 浏览:4611
最佳答案
原因是,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。
回答时间:2010/3/12 20:57:13 | 回答者:jeffreysu
其他参考答案(0)
提交失败!请检查错误!错误信息:

注:以上所有信息由网友提供,仅供交流、参考,均不代表盛派网络言论,如果有任何问题或不妥,请立即联系我们

以下信息或许对您有用: