从浏览文件夹之外加载查看 [英] Load a View from outside the Views folder

查看:157
本文介绍了从浏览文件夹之外加载查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作了asp.net的MVC一个widgetmanager,并获得主要部分的工作,我需要从默认视图文件夹之外的视图加载。我得到了以下文件夹结构:

I'm working on a widgetmanager for asp.net mvc and to get the main part to work, I need to load in a view from outside the default views folder. I got the following folder structure:

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

... - Views - Widgets |- Views

我需要从加载〜/小工具/浏览次数内的意见
我不知道我是否应该从头开始编写一个视图引擎或做其他事,所以请随时回答:)

I need the views to be loaded from inside ~/Widgets/Views I'm not sure if I should be writing a Viewengine from scratch or do something else so please feel free to answer :)

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

p.S. The widgetmanager is called S3WidgetManager and can be found on GitHub

推荐答案

您可以编写一个<一个href=\"http://www.leonamarant.com/2011/02/17/adding-a-custom-directory-to-razor-view-engine-partial-view-locations-in-asp-net-mvc3/\"相对=nofollow>自定义视图引擎和玩以下基本属性,让你自定义的视图的位置:

You could write a custom view engine and play around with the following base properties which allow you to customize the location of the views:

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

这篇关于从浏览文件夹之外加载查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆