【发布时间】:2009-07-25 18:59:03
【问题描述】:
我目前有以下路线:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.gif/{*pathInfo}");
MvcRoute.MappUrl("{controller}/{action}/{ID}")
.WithDefaults(new { controller = "home", action = "index", ID = 0 })
.WithConstraints(new { controller = "..." })
.AddWithName("default", routes)
.RouteHandler = new MvcRouteHandler();
MvcRoute.MappUrl("{title}/{ID}")
.WithDefaults(new { controller = "special", action = "Index" })
.AddWithName("view", routes)
.RouteHandler = new MvcRouteHandler();
SpecialController 有一个方法:public ActionResult Index(int ID)
每当我将浏览器指向http://hostname/test/5 时,我都会收到以下错误:
参数字典包含“SpecialController”中方法“System.Web.Mvc.ActionResult Index(Int32)”的不可为空类型“System.Int32”的参数“ID”的空条目。要使参数可选,其类型应该是引用类型或 Nullable 类型。
参数名称:参数
说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
这是为什么呢?我使用了mvccontrib路由调试器,看来路由可以按预期访问了。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing