【发布时间】:2010-09-27 08:41:50
【问题描述】:
我有一个名为 Members 的区域,并且在 MembersAreaRegistration 文件中注册了以下路由:
context.MapRoute(
"Members_Profile",
"Members/Profile/{id}",
new { controller = "Profile", action = "Index", id = UrlParameter.Optional },
new string[] { "MyProject.Web.Mvc.Areas.Members.Controllers" }
);
context.MapRoute(
"Members_default",
"Members/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "MyProject.Web.Mvc.Areas.Members.Controllers" }
);
我希望能够映射以下 URL:
~/Members (should map ~/Members/Home/Index )
~/Members/Profile/3 (should map ~/Members/Profile/Index/3)
使用此路由注册,一切正常。但是,我添加了以下网址:
~/Members/Profile/Add
我得到了错误:
“参数字典包含一个 null 条目,用于 'MyProject.Web.Mvc.Areas 中的方法 'System.Web.Mvc.ActionResult Index(Int32)' 的不可为空类型 'System.Int32' 的参数 'id' .Members.Controllers.ProfileController'。可选参数必须是引用类型、可空类型或声明为可选参数。"
我也想要网址
~/Members/Profile/Edit/3
为了让所有这些 URL 正常工作,我应该修改什么?
【问题讨论】:
标签: asp.net-mvc-2 asp.net-mvc-routing asp.net-mvc-areas