通常、これを処理する領域を使用します。
var url = Url.Action("Index", "Home", new {Area = "Myarea"});
var url = Url.Action("Index", "Home", new {Area = "area2"});
uはuがカスタムViewEngineを使用することができますこの方法のように、あなたのアドオンの他のプロジェクトを好きなら。このように 最初にこのような経路ルールを追加する:
routes.MapRoute(
name: "app",
url: "{application}/{controller}/{action}/{id}",
defaults: new {application = "MyApplication1", controller = "Panel", action = "Index", id = UrlParameter.Optional }
);
秒: URアプリケーションの仮想パスを追加:
public class CustomAreaViewEngine : VirtualPathProviderViewEngine
{
public CustomAreaViewEngine()
{
MasterLocationFormats = new string[]
{
"~/Views/{1}/{0}.master",
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.master",
"~/Views/Shared/{0}.cshtml",
"~/Areas/{2}/Views/{1}/{0}.master",
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.master",
"~/Areas/{2}/Views/Shared/{0}.cshtml",
"~/Areas/{2}/{2}/Views/{1}/{0}.master",
"~/Areas/{2}/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/{2}/Views/Shared/{0}.master",
"~/Areas/{2}/{2}/Views/Shared/{0}.cshtml",
"~/{2}/Views/{1}/{0}.master",
"~/{2}/Views/{1}/{0}.cshtml",
"~/{2}/Views/Shared/{0}.master",
"~/{2}/Views/Shared/{0}.cshtml",
"~/{2}/{2}/Views/{1}/{0}.master",
"~/{2}/{2}/Views/{1}/{0}.cshtml",
"~/{2}/{2}/Views/Shared/{0}.master",
"~/{2}/{2}/Views/Shared/{0}.cshtml",
};
ViewLocationFormats = new string[]
{
"~/Areas/{2}/Views/{1}/{0}.aspx",
"~/Areas/{2}/Views/{1}/{0}.ascx",
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.aspx",
"~/Areas/{2}/Views/Shared/{0}.ascx",
"~/Areas/{2}/Views/Shared/{0}.cshtml",
"~/Areas/{2}/{2}/Views/{1}/{0}.aspx",
"~/Areas/{2}/{2}/Views/{1}/{0}.ascx",
"~/Areas/{2}/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/{2}/Views/Shared/{0}.aspx",
"~/Areas/{2}/{2}/Views/Shared/{0}.ascx",
"~/Areas/{2}/{2}/Views/Shared/{0}.cshtml",
"~/{2}/Views/{1}/{0}.aspx",
"~/{2}/Views/{1}/{0}.ascx",
"~/{2}/Views/{1}/{0}.cshtml",
"~/{2}/Views/Shared/{0}.aspx",
"~/{2}/Views/Shared/{0}.ascx",
"~/{2}/Views/Shared/{0}.cshtml",
"~/{2}/{2}/Views/{1}/{0}.aspx",
"~/{2}/{2}/Views/{1}/{0}.ascx",
"~/{2}/{2}/Views/{1}/{0}.cshtml",
"~/{2}/{2}/Views/Shared/{0}.aspx",
"~/{2}/{2}/Views/Shared/{0}.ascx",
"~/{2}/{2}/Views/Shared/{0}.cshtml",
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx",
"~/Views/Shared/{0}.cshtml"
};
PartialViewLocationFormats = ViewLocationFormats;
}
およびuはGlobal.asaxのを変更sould:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomAreaViewEngine());
}
を
最後に、メインのアプリケーション名前空間にurコントローラを実装する必要があります。 このように説明する必要はありますか?
あなたがMyModulesのようなカスタムディレクトリにurアプリケーションを置くことができるCustomAreaViewEngineを開発したい場合は、
「エリア」https://msdn.microsoft.com/en-us/library/ee671793(v=vs.100)を試してみませんか?aspx –