I am creating advanced site that is based in 99% on one view. I have created the following code which is responsible to point all controllers actions which dont have corresponding view to universal view: ~/Views/Shared/UniversalView.cshtml.
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
foreach (IViewEngine engine in ViewEngines.Engines)
{
if (engine is RazorViewEngine)
{
RazorViewEngine razorEngine = (RazorViewEngine)engine;
var locationFormats = razorEngine.ViewLocationFormats;
List<string> l = new List<string>(locationFormats);
l.Add("~/Views/Shared/UniversalView.cshtml");
razorEngine.ViewLocationFormats = l.ToArray();
}
}
}
I am preety sure that there will be much better method to achive that effect. Any ideas?