2011-05-31 101 views
1

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

... - 查看 - 小工具 | - 查看

我需要的意见,从装载内部〜/小工具/浏览次数 我不知道如果我应该从头开始编写Viewengine或做其他事情,所以请随时回答:)

pS该widgetmanager被称为S3WidgetManager,可以在GitHub

找到

回答

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" 
}; 
+0

当我这样做,Html.RouteLink和默认模型变量不再被认可(probaly以上,但多数民众赞成我用现在)。在默认视图文件夹中拖放文件后,它可以正常工作,但是我不想在那里 – MrSoundless 2011-05-31 07:30:18

+4

@MrSoundless,你需要在你的自定义文件夹中放置一个web.config文件。与'〜/ Views/web.config'中使用的一样。不要忘记,在解析视图中的引用时,Razor会查找此文件中定义的名称空间。或者,如果您不想使用这样的web.config文件,则需要在视图中导入正确的使用,以便将帮助器引入范围。 – 2011-05-31 07:31:06

+0

非常感谢您的支持,并不知道这件事! – MrSoundless 2011-05-31 07:34:43