Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 Razor - How to stop the view engine from searching the aspx and ascx pages?

I had a small bug in a view and noticed that the view engine was searching not only for my razor views but for aspx/ascx pages. (My bug is fixed)

Is there a way to tell it to only search the Razor view engine?

Here is the error message that was displayed:

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/BO/Views/Organization/Index.aspx
~/Areas/BO/Views/Organization/Index.ascx
~/Areas/BO/Views/Shared/Index.aspx
~/Areas/BO/Views/Shared/Index.ascx
~/Views/Organization/Index.aspx
~/Views/Organization/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Areas/BO/Views/Organization/Index.cshtml
~/Areas/BO/Views/Organization/Index.vbhtml
~/Areas/BO/Views/Shared/Index.cshtml
~/Areas/BO/Views/Shared/Index.vbhtml
~/Views/Organization/Index.cshtml
~/Views/Organization/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
like image 537
Omnia9 Avatar asked Oct 11 '11 14:10

Omnia9


People also ask

Which view engine is better razor or ASPX?

The Razor View Engine is a bit slower than the ASPX View Engine. Razor provides a new view engine with streamlined code for focused templating. Razor's syntax is very compact and improves readability of the markup and code. By default MVC supports ASPX (web forms) and Razor View Engine.

What is the difference between Razor and ASPX engine in MVC?

Razor Engine is an advanced view engine that was introduced with MVC3. This is not a new language but it is a new markup syntax. Web Form Engine is the default view engine for the Asp.net MVC that is included with Asp.net MVC from the beginning.

How can we remove the default view engine?

Removing the Web Form (ASPX) view engine We can remove all the view engines and add only Razor view engine by using Application_Start event of Global. asax. cs file like as: protected void Application_Start() { //Remove All Engine ViewEngines.

What is razor control in MVC?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.


1 Answers

You need to remove the WebFormsViewEngine from ViewEngine.Engines so that it only contains a RazorViewEngine.

For example:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
like image 173
SLaks Avatar answered Nov 15 '22 17:11

SLaks