4

私は、メンバーと呼ばれるエリアと、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)

このルート登録により、すべてが正常に機能します。ただし、次の URL を追加しました。

~/Members/Profile/Add 

エラーが発生しました:

「パラメーター ディクショナリには、'MyProject.Web.Mvc.Areas.Members. Controllers.ProfileController'. オプションのパラメーターは、参照型または null 許容型であるか、オプションのパラメーターとして宣言する必要があります。"

URLもお願いします

~/Members/Profile/Edit/3

このすべての URL が正しく機能するようにするには、何を変更すればよいですか?

4

1 に答える 1

4

すでに定義したルートの前に、さらにいくつかのルートを追加する必要があります。これは、これらのルートが、既にあるより一般的なルートの前に選択する必要があるためです。

context.MapRoute(
     "Members_Profile",
     "Members/Profile/Add",
     new { controller = "Profile", action = "Add" },
     new string[] { "MyProject.Web.Mvc.Areas.Members.Controllers" }
     );

context.MapRoute(
     "Members_Profile",
     "Members/Profile/Edit/{Id}",
     new { controller = "Profile", action = "Edit", id = UrlParameter.Optional },
     new string[] { "MyProject.Web.Mvc.Areas.Members.Controllers" }
     );
于 2010-09-27T09:14:45.957 に答える