我在 MembersAreaRegistration 文件中有一个名为 Members 的区域和以下注册路线:
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)
使用此路线注册,一切正常。但是,我添加了以下 URL:
~/Members/Profile/Add
我得到了错误:
“参数字典包含‘MyProject.Web.Mvc.Areas.Members’中方法‘System.Web.Mvc.ActionResult Index(Int32)’的不可为空类型‘System.Int32’的参数‘id’的空条目。 Controllers.ProfileController'。可选参数必须是引用类型、可空类型或声明为可选参数。”
我也想要网址
~/Members/Profile/Edit/3
为了使所有这些 URL 正常工作,我应该修改什么?