MikeSW はルートに近づいていますが、フランチャイジーのページが企業のページとコントローラーを共有することを望まないようです。他にもいくつか考えがあります。
routes.MapRoute(null, // do not name your routes, they are "magic strings"
"{tenant}/{controller}/{action}",
new
{
// strongly type controller, action, and area names using T4MVC
controller = MVC.Home.Name,
action = MVC.Home.ActionNames.Index,
// it sounds here like you want this controller for franchisees only,
// so corporate pages will use other controllers. if this is the case,
// tenant="default" // require the parameter by not supplying a default
});
ルートに名前を付けない理由は、ルートに名前を付けないと、一部の html ヘルパーおよびコントローラー メソッドで特定のオーバーロードを使用する必要があるためです。RedirectToRoute
、@Html.RouteLink
、 などのメソッドのオーバーロードの多くは@Url.RouteUrl
、最初の引数としてルート名を取ります。ルートから名前を省略することで、ルート パラメーターと HTTP メソッドのみに依存するオーバーロードを使用してコントローラーとアクションを解決する必要があります。( T4MVCは、これらのメソッドへの引数の領域、コントローラー、およびアクション名を厳密に型指定できるため、ここでも役立ちます。)
MVC は、ビューがレンダリングされる URL で「アンビエント」ルート パラメーターを自動的に使用します。そのため、URL にアクセスdomain.com/atl
して にリンクしたい場合はdomain.com/atl/stuff
、次のようなハイパーリンクを出力できます。
@Html.RouteLink("Stuff", new
{
// this will render a link with the URL domain.com/atl/stuff
controller = MVC.Stuff.Name,
action = MVC.Stuff.ActionNames.Index,
// you do not need to include franchisee
})
<a>
(通常の HTMLタグの href パラメーターの URL のみをレンダリングする場合は、@Url.RouteUrl
代わりに使用してください。)
一方、あるフランチャイズ サイトから別のフランチャイズ サイトにリンクする場合は、フランチャイズ パラメーターを指定する必要があります。
@Html.RouteLink("Another franchisee in this state", new
{
// this will render a link with the URL domain.com/macon
controller = MVC.Home.Name,
action = MVC.Home.ActionNames.Index,
franchisee = "macon"
})