In ASP. in. net mvc 3.0, after a new project is created, a file such as _ ViewStart will appear in the Views directory. cshtml (corresponding to Razor, C #, or _ ViewStart. vbhtml ).
This file will be stored in all views (. cshtml) is executed before execution, mainly used for some inconvenient or not in the master (_ Layout. cshtml). For example, you have many masters that do not have an inheritance relationship or do not use a single page of the master.
In _ ViewStart. cshtml, we can define some parameters or make some judgments. There is no difference between the definition process and syntax and the general page.
In addition to the provided default functions, you can also define a class, such as MyViewStart, using System. web. mvc. viewStartPage is used as the base class and in _ ViewStart. reference MyViewStart in cshtml (add to the first line of the file: @ inherits MyNamespace. myViewStart ).
If you create ViewEngine by yourself, there will be a runViewStartPages parameter in the RazorView constructor. If it is false, you can skip ViewStartPage and execute it if it is true.