diff --git a/LearningMVC.sln b/LearningMVC.sln index 7a7b591..df8b3f4 100644 --- a/LearningMVC.sln +++ b/LearningMVC.sln @@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControllersAndActions", "Co EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControllersAndActions.Tests", "ControllersAndActions.Tests\ControllersAndActions.Tests.csproj", "{3C486608-0E84-4D27-90B3-A4867399D9E2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Views", "Views\Views.csproj", "{F99363A1-BC8B-4136-BCC5-87931F1D8899}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -75,6 +77,10 @@ Global {3C486608-0E84-4D27-90B3-A4867399D9E2}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C486608-0E84-4D27-90B3-A4867399D9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU {3C486608-0E84-4D27-90B3-A4867399D9E2}.Release|Any CPU.Build.0 = Release|Any CPU + {F99363A1-BC8B-4136-BCC5-87931F1D8899}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F99363A1-BC8B-4136-BCC5-87931F1D8899}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F99363A1-BC8B-4136-BCC5-87931F1D8899}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F99363A1-BC8B-4136-BCC5-87931F1D8899}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Views/App_Start/RouteConfig.cs b/Views/App_Start/RouteConfig.cs new file mode 100644 index 0000000..5452e70 --- /dev/null +++ b/Views/App_Start/RouteConfig.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; + +namespace Views +{ + public class RouteConfig + { + public static void RegisterRoutes(RouteCollection routes) + { + routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); + + routes.MapRoute( + name: "Default", + url: "{controller}/{action}/{id}", + defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } + ); + } + } +} diff --git a/Views/Controllers/HomeController.cs b/Views/Controllers/HomeController.cs new file mode 100644 index 0000000..66fa764 --- /dev/null +++ b/Views/Controllers/HomeController.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Views.Controllers +{ + public class HomeController : Controller + { + public ActionResult Index() + { + ViewBag.Message = "Hello, World"; + ViewBag.Time = DateTime.Now.ToShortTimeString(); + return View("DebugData"); + } + + public ActionResult List() + { + return View(); + } + } +} \ No newline at end of file diff --git a/Views/Global.asax b/Views/Global.asax new file mode 100644 index 0000000..9b560b2 --- /dev/null +++ b/Views/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.cs" Inherits="Views.MvcApplication" Language="C#" %> diff --git a/Views/Global.asax.cs b/Views/Global.asax.cs new file mode 100644 index 0000000..eebd7cc --- /dev/null +++ b/Views/Global.asax.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; +using Views.Infrastructure; + +namespace Views +{ + public class MvcApplication : System.Web.HttpApplication + { + protected void Application_Start() + { + AreaRegistration.RegisterAllAreas(); + RouteConfig.RegisterRoutes(RouteTable.Routes); + + //ViewEngines.Engines.Clear(); + ViewEngines.Engines.Add(new DebugDataViewEngine()); + } + } +} diff --git a/Views/Infrastructure/DebugDataView.cs b/Views/Infrastructure/DebugDataView.cs new file mode 100644 index 0000000..797ef32 --- /dev/null +++ b/Views/Infrastructure/DebugDataView.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Web; +using System.Web.Mvc; + +namespace Views.Infrastructure +{ + public class DebugDataView : IView + { + public void Render(ViewContext viewContext, TextWriter writer) + { + Write(writer, "---Routing Data---"); + foreach (string key in viewContext.RouteData.Values.Keys) + { + Write(writer, "Key: {0}, Value: {1}", key, viewContext.RouteData.Values[key]); + } + + Write(writer, "---View Data---"); + foreach (string key in viewContext.ViewData.Keys) + { + Write(writer, "Key: {0}, Value: {1}", key, viewContext.ViewData[key]); + } + } + + private void Write(TextWriter writer, string template, params object[] values) + { + writer.Write(string.Format(template, values) + "

"); + } + } +} \ No newline at end of file diff --git a/Views/Infrastructure/DebugDataViewEngine.cs b/Views/Infrastructure/DebugDataViewEngine.cs new file mode 100644 index 0000000..e68053f --- /dev/null +++ b/Views/Infrastructure/DebugDataViewEngine.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Views.Infrastructure +{ + public class DebugDataViewEngine : IViewEngine + { + public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) + { + if (viewName == "DebugData") + { + return new ViewEngineResult(new DebugDataView(), this); + } + else + { + return new ViewEngineResult(new string[] { "no view (Debug Data View Engine)" }); + } + } + + public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) + { + return new ViewEngineResult(new string[] { "No view (Debug Data View Engine)" }); + } + + public void ReleaseView(ControllerContext controllerContext, IView view) + { + + } + } +} \ No newline at end of file diff --git a/Views/Properties/AssemblyInfo.cs b/Views/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..917a840 --- /dev/null +++ b/Views/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Views")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Views")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f99363a1-bc8b-4136-bcc5-87931f1d8899")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Views/Views.csproj b/Views/Views.csproj new file mode 100644 index 0000000..9f7ca8c --- /dev/null +++ b/Views/Views.csproj @@ -0,0 +1,158 @@ + + + + + + Debug + AnyCPU + + + 2.0 + {F99363A1-BC8B-4136-BCC5-87931F1D8899} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Views + Views + v4.5.2 + true + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + true + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + + + + + + + + + + + + + + + + + + + + ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll + + + ..\packages\Microsoft.AspNet.Webpages.3.2.3\lib\net45\System.Web.Webpages.dll + + + ..\packages\Microsoft.AspNet.Webpages.3.2.3\lib\net45\System.Web.Webpages.Deployment.dll + + + ..\packages\Microsoft.AspNet.Webpages.3.2.3\lib\net45\System.Web.Webpages.Razor.dll + + + ..\packages\Microsoft.AspNet.Webpages.3.2.3\lib\net45\System.Web.Helpers.dll + + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll + + + + + + + + + + + Global.asax + + + + + + + + + + Web.config + + + Web.config + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 7336 + / + http://localhost:7336/ + False + False + + + False + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/Views/Views/web.config b/Views/Views/web.config new file mode 100644 index 0000000..cf3c30f --- /dev/null +++ b/Views/Views/web.config @@ -0,0 +1,42 @@ + + + + + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Views/Web.Debug.config b/Views/Web.Debug.config new file mode 100644 index 0000000..fae9cfe --- /dev/null +++ b/Views/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Views/Web.Release.config b/Views/Web.Release.config new file mode 100644 index 0000000..da6e960 --- /dev/null +++ b/Views/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Views/Web.config b/Views/Web.config new file mode 100644 index 0000000..43634a3 --- /dev/null +++ b/Views/Web.config @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Views/packages.config b/Views/packages.config new file mode 100644 index 0000000..262d240 --- /dev/null +++ b/Views/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file