Remove the apsx View engine and web. config in the View folder.
<>
Remove the apsx view engine when using the Rezor view Engine
Global. asax File
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. http; using System. web. mvc; using System. web. routing; namespace MvcApp {// Note: Instructions on enabling IIS6 or IIS7 Classic mode, // visit the http://go.microsoft.com /? LinkId = 9394801 public class MvcApplication: System. web. httpApplication {protected void Application_Start () {AreaRegistration. registerAllAreas (); WebApiConfig. register (GlobalConfiguration. configuration); FilterConfig. registerGlobalFilters (GlobalFilters. filters); RouteConfig. registerRoutes (RouteTable. routes); // we usually use the Razor view engine, so there is no need for MVC to search for the aspx view engine, so we can remove the aspx view engine. In this way, each time a view is loaded, it will be faster (because it will consume performance to search for the aspx view engine every time a view is loaded. We can create a Home controller without creating an Index view. When we access/Home/Index, we will prompt that the view cannot be found, we can see that after MVC finds the aspx and Razor views, if they are not found, an error will be reported.) // Why should I write the code for removing the view engine in this Global. what about the asax file? That's because the website is started. I will remove it first. // Remove aspx view engine // ViewEngines. Engines. RemoveAt (0); // This is a Razor view engine // ViewEngines. Engines. RemoveAt (1 );}}}
In the MVC project, we found that there is also a web. config configuration file in the view. What does this configuration file do?
The view we see is essentially a front-end class, which will be compiled into a front-end page class when our view engine finds it for the first time. After compilation, you need to inherit this front-end page class from a webViewPage <TModel> generic class or WebViewPage class (Note: The WebViewPage class is the parent class of the webViewPage <TModel> class)
(After reading the following code, we will find that the parent class of the front-end page class generated after the View is compiled is specified in the web. config file under the View folder)
Open the web. config file and you will see this section in it.
<pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> </namespaces> </pages>
If we delete the web. config file in the View folder, the following error will pop up.
When we access a view page, for example,/Home/Index, the view engine will compile this Index view. during compilation, we will find that the view is found, it does not know who the parent class of the compiled front-end page class is.
Therefore, it is concluded that the web. config file under the View folder is used to tell the View engine how to compile the foreground page class of the View and determine that the parent class of the current page class is WebViewPage.
The configuration in the web. config does not need to be manually changed or deleted.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.