你可以写一个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"
};
当我这样做,Html.RouteLink和默认模型变量不再被认可(probaly以上,但多数民众赞成我用现在)。在默认视图文件夹中拖放文件后,它可以正常工作,但是我不想在那里 – MrSoundless 2011-05-31 07:30:18
@MrSoundless,你需要在你的自定义文件夹中放置一个web.config文件。与'〜/ Views/web.config'中使用的一样。不要忘记,在解析视图中的引用时,Razor会查找此文件中定义的名称空间。或者,如果您不想使用这样的web.config文件,则需要在视图中导入正确的使用,以便将帮助器引入范围。 – 2011-05-31 07:31:06
非常感谢您的支持,并不知道这件事! – MrSoundless 2011-05-31 07:34:43