<>
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: For instructions on enabling IIS6 or IIS7 Classic mode,//please visit the Http://go.microsof t.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); Normally we use the Razor view engine, so there is no need for MVC to find the ASPX view engine, so you can remove the ASPX view engine. This will be a bit faster each time the view is loaded (because it is performance-intensive to find the ASPX view engine every time the view is loaded.) We can create a Home controller, do not create an index view of it, when we visit/home/index, we will be prompted to find the view, we can see MVC to find the ASPX and razor view, not found, will not find the view of the error)//Why the The code to remove the view engine is written in this Global.asax file? That's because the site starts, I'll remove it first. Removal of the ASPX View engine//viewengines.engines.removeat (0); This is a one-time razor view engine ViewEngines.Engines.RemoveAt (1); } }}
In the MVC project, we found that there is also a Web. config file in the view, so what does this configuration file do?
The view that we see is essentially a front-end class that, when our view engine first finds it, compiles it into a front-end page class, and after compiling it, we need to inherit the 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 looking at the code below, 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)
We open this Web. config file and we can see that there's a
<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 this view folder, it will explode the following error
When we visit a view page, such as/home/index, the View engine compiles the index view and, when compiled, finds the view, and it does not know who the parent class of the front-end page class was compiled.
So come to the conclusion that the Web. config file under the View folder is about telling the view engine how to compile the foreground page class for the view and making the parent class of the current page class Webviewpage
The configuration in this web. config does not require us to manually change anything, nor can we delete
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Removal of the APSX view engine and the role of Web. config under the View folder