我是否可以在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 關注
- 646 瀏覽
添加回答
舉報
0/150
提交
取消