从Views文件夹外部加载视图

时间:2011-05-31 07:00:36

标签: asp.net-mvc-3

我正在为asp.net mvc创建一个widgetmanager并让主要部分工作,我需要从默认视图文件夹外部加载一个视图。我有以下文件夹结构:

... - 意见 - 小工具 | - 视图

我需要从〜/ Widgets / Views中加载视图 我不确定是否应该从头开始编写Viewengine或做其他事情,所以请随时回答:)

P.S。 widgetmanager被称为S3WidgetManager,可以在GitHub上找到

1 个答案:

答案 0 :(得分:2)

您可以编写custom view engine并使用以下基本属性,以便自定义视图的位置:

base.ViewLocationFormats
base.PartialViewLocationFormats
base.MasterLocationFormats
base.AreaViewLocationFormats
base.AreaPartialViewLocationFormats
base.AreaMasterLocationFormats

这是他们的默认值:

base.AreaViewLocationFormats = new string[] 
{ 
    "~/Areas/{2}/Views/{1}/{0}.cshtml", 
    "~/Areas/{2}/Views/{1}/{0}.vbhtml", 
    "~/Areas/{2}/Views/Shared/{0}.cshtml", 
    "~/Areas/{2}/Views/Shared/{0}.vbhtml" 
};
base.AreaMasterLocationFormats = new string[] 
{ 
    "~/Areas/{2}/Views/{1}/{0}.cshtml", 
    "~/Areas/{2}/Views/{1}/{0}.vbhtml", 
    "~/Areas/{2}/Views/Shared/{0}.cshtml", 
    "~/Areas/{2}/Views/Shared/{0}.vbhtml" 
};
base.AreaPartialViewLocationFormats = new string[] 
{ 
    "~/Areas/{2}/Views/{1}/{0}.cshtml", 
    "~/Areas/{2}/Views/{1}/{0}.vbhtml", 
    "~/Areas/{2}/Views/Shared/{0}.cshtml", 
    "~/Areas/{2}/Views/Shared/{0}.vbhtml" 
};
base.ViewLocationFormats = new string[] 
{ 
    "~/Views/{1}/{0}.cshtml", 
    "~/Views/{1}/{0}.vbhtml", 
    "~/Views/Shared/{0}.cshtml", 
    "~/Views/Shared/{0}.vbhtml" 
};
base.MasterLocationFormats = new string[] 
{ 
    "~/Views/{1}/{0}.cshtml", 
    "~/Views/{1}/{0}.vbhtml", 
    "~/Views/Shared/{0}.cshtml", 
    "~/Views/Shared/{0}.vbhtml" 
};
base.PartialViewLocationFormats = new string[] 
{ 
    "~/Views/{1}/{0}.cshtml", 
    "~/Views/{1}/{0}.vbhtml", 
    "~/Views/Shared/{0}.cshtml", 
    "~/Views/Shared/{0}.vbhtml" 
};
base.FileExtensions = new string[] 
{ 
    "cshtml", 
    "vbhtml" 
};