Created
March 27, 2013 22:28
-
-
Save bbilginn/5258693 to your computer and use it in GitHub Desktop.
Nested-Folder-Structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Note: For instructions on enabling IIS6 or IIS7 classic mode, | |
' visit http://go.microsoft.com/?LinkId=9394802 | |
Imports System.Web.Http | |
Imports System.Web.Optimization | |
Public Class MvcApplication | |
Inherits System.Web.HttpApplication | |
Sub Application_Start() | |
AreaRegistration.RegisterAllAreas() | |
WebApiConfig.Register(GlobalConfiguration.Configuration) | |
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters) | |
RouteConfig.RegisterRoutes(RouteTable.Routes) | |
BundleConfig.RegisterBundles(BundleTable.Bundles) | |
ViewEngines.Engines.Add(NestedView.Engine) 'Ruhumuz huzura erdi! | |
End Sub | |
End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.IO | |
Imports System.Web.Mvc | |
Imports System.Web | |
Public NotInheritable Class NestedView | |
''' <summary> | |
''' Global.asax, Application_Start() içerisinde ViewEngines.Engines.Add(NestedView.Engine) olarak tanımlanmalı. | |
''' </summary> | |
''' <returns>RazorViewEngine</returns> | |
''' <remarks></remarks> | |
Public Shared Function Engine() As RazorViewEngine | |
Dim vList As New List(Of String) | |
Dim pList As New List(Of String) | |
Dim mList As New List(Of String) | |
Dim dir As New DirectoryInfo(HttpContext.Current.Server.MapPath("~/Views/")) | |
ViewEngines.Engines.Clear() 'Geçmiş siliniyor. -Bu satır olmadan zaten standart yapı dahil olur. Aşağıdaki 3 satıra ihtiyaç olmaz. | |
vList.Add("~/Views/{1}/{0}.vbhtml") 'Standart yapı yeniden ekleniyor. -> "~/Views/Home/Index.vbhtml" | |
pList.Add("~/Views/Shared/{0}.vbhtml") 'Standart yapı yeniden ekleniyor. -> "~/Views/Shared/_Layout.vbhtml" | |
mList.Add("~/Views/Shared/{0}.vbhtml") 'Standart yapı yeniden ekleniyor. -> "~/Views/Shared/_pLogOnPartial.vbhtml" | |
For Each item As DirectoryInfo In dir.GetDirectories ' "~/Views/" klasörü taranıyor. | |
vList.Add("~/Views/" + item.Name + "/{1}/{0}.vbhtml") 'Views altı klasör desenine uygun view yapısı ekleniyor. -> "~/Views/TESTS/First/Index.vbhtml" | |
pList.Add("~/Views/" + item.Name + "/_Shared/Partial/{0}.vbhtml") 'Views altı klasör desenine uygun partial yapısı ekleniyor. -> "~/Views/TESTS/_Shared/Partial/_pLogOnPartial.vbhtml" | |
mList.Add("~/Views/" + item.Name + "/_Shared/Layout/{0}.vbhtml") 'Views altı klasör desenine uygun layout yapısı ekleniyor. -> "~/Views/TESTS/_Shared/Layout/Master1.vbhtml" | |
Next | |
Dim customEngine As New RazorViewEngine | |
customEngine.ViewLocationFormats = vList.ToArray 'Location-Format Set ediliyor. | |
customEngine.PartialViewLocationFormats = pList.ToArray 'Location-Format Set ediliyor. | |
customEngine.MasterLocationFormats = mList.ToArray 'Location-Format Set ediliyor. | |
Return customEngine | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment