Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以更改ASP.Net MVC 3应用程序的物理视图的搜索顺序吗_Asp.net_Asp.net Mvc 3_Razor - Fatal编程技术网

我可以更改ASP.Net MVC 3应用程序的物理视图的搜索顺序吗

我可以更改ASP.Net MVC 3应用程序的物理视图的搜索顺序吗,asp.net,asp.net-mvc-3,razor,Asp.net,Asp.net Mvc 3,Razor,我注意到Asp.NETMVC3在.cshtml文件之前搜索.aspx文件。我可以更改搜索顺序吗?如何做到这一点 背景资料 调试时,我遇到以下异常: The view 'Reset' or its master was not found. The following locations were searched: ~/Views/Demo/Reset.aspx ~/Views/Demo/Reset.ascx ~/Views/Shared/Reset.aspx ~/Views/Shared/Re

我注意到Asp.NETMVC3在.cshtml文件之前搜索.aspx文件。我可以更改搜索顺序吗?如何做到这一点

背景资料 调试时,我遇到以下异常:

The view 'Reset' or its master was not found. The following locations were searched:
~/Views/Demo/Reset.aspx
~/Views/Demo/Reset.ascx
~/Views/Shared/Reset.aspx
~/Views/Shared/Reset.ascx
~/Views/Demo/Reset.cshtml
~/Views/Demo/Reset.vbhtml
~/Views/Shared/Reset.cshtml
~/Views/Shared/Reset.vbhtml
我由此得出结论,首先搜索旧的.aspx视图

由于我将我的站点转换为MVC3,将所有视图转换为Razor,因此我希望先搜索.cshtml文件。我认为这对性能会更好。

是的

但在非调试配置中,文件位置是缓存的,因此它只在第一次查找时有用。我不会担心的。

多亏我找到了我想要的语法:

我在
Global.asax.cs
中将其添加到我的
应用程序\u Start

    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new RazorViewEngine()); 
    // ViewEngines.Engines.Add(new WebFormViewEngine()); <-- uncomment if needed
ViewEngines.Engines.Clear();
添加(新的RazorViewEngine());

//添加(新WebFormViewEngine());如果您根本不使用Aspx,则无需添加
WebFormViewEngine
。然而,正如Craig所提到的,对于在服务器上运行的应用程序来说,这并不重要。。。但是这是缓存的,所以它的性能会很好。