我是否可以在ASP.NETMVC中指定“搜索视图”的自定义位置?我的MVC项目有以下布局:/控制器/演示/Demo/DemoArea1控制器/Demo/DemoArea 2控制器等等.。/意见/演示/Demo/DemoArea 1/Index.aspx/Demo/DemoArea 2/Index.aspx但是,当我有了这个DemoArea1Controller:public class DemoArea1Controller : Controller{
public ActionResult Index()
{
return View();
}}我得到“视图‘索引’或它的主错误找不到”错误,与通常的搜索位置。如何指定“Demo”视图子文件夹中“Demo”命名空间搜索中的控制器?
3 回答
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
public class CustomViewEngine : WebFormViewEngine{
public CustomViewEngine()
{
var viewLocations = new[] {
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx",
"~/AnotherPath/Views/{0}.ascx"
// etc
};
this.PartialViewLocationFormats = viewLocations;
this.ViewLocationFormats = viewLocations;
}}protected void Application_Start(){
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomViewEngine());}- 3 回答
- 0 关注
- 659 浏览
添加回答
举报
0/150
提交
取消
