Please look at the following things first:
The View "Index" or its master view is not found , or there is no search location supported by the view engine. The following locations were searched :
~/views/home/index.aspx
~/views/home/index.ascx
~/views/shared/index.aspx
~/views/shared/index.ascx
~/views/home/index.cshtml
~/views/home/index.vbhtml
~/views/shared/index.cshtml
~/views/shared/index.vbhtml
Copyright belongs to the second brother and blog Garden Common All, welcome to reprint and share knowledge. Reprint please specify the source!
Mvc4 and MVC3 are found in this way, where *.aspx and *.ascx and *.vbhtml are what we don't need.
We can imagine that no matter what method is used here, must be at least 4 times to access the file system and determine whether the corresponding file exists, will find our index.cshtml, such overhead small applications can be ignored, if the concurrency of TENS (in short, very large, specific) must have a certain impact on performance.
How to avoid, not to find *.aspx,*.ascx and *.vbhtml?
After a few tossing, we succeeded in finding a solution:
There are two view engines in MVC, Webformengine and Razorengine, and the solution is to remove webformengine without using WebForm, Then remove the Razorengine and add the rewritten razorengine.
The removed code writes like this in the Application_Start method of Global.ascx.cs:
ViewEngines.Engines.Clear ();
To override the Razorengine method:
public class Engine:razorviewengine
{
Public Engine ()
{
Base. Areaviewlocationformats = new string[]
{
"~/areas/{2}/views/{1}/{0}.cshtml",
"~/areas/{2}/views/shared/{0}.cshtml",
};
Base. Areamasterlocationformats = new string[]
{
"~/areas/{2}/views/{1}/{0}.cshtml",
"~/areas/{2}/views/shared/{0}.cshtml",
};
Base. Areapartialviewlocationformats = new string[]
{
"~/areas/{2}/views/{1}/{0}.cshtml",
"~/areas/{2}/views/shared/{0}.cshtml",
};
Base. Viewlocationformats = new string[]
{
"~/views/{1}/{0}.cshtml",
"~/views/shared/{0}.cshtml",
};
Base. Masterlocationformats = new string[]
{
"~/views/{1}/{0}.cshtml",
"~/views/shared/{0}.cshtml",
};
Base. Partialviewlocationformats = new string[]
{
"~/views/{1}/{0}.cshtml",
"~/views/shared/{0}.cshtml",
};
Base. Fileextensions = new string[]
{
"Cshtml",
};
}
}
Then add the overridden view engine:
VIEWENGINES.ENGINES.ADD (New Engine ());
Copyright belongs to the second brother and blog Garden Common All, welcome to reprint and share knowledge. Reprint please specify the source!
The final Application_Start method is as follows:
MVC View Engine Optimization