diff --git a/LearningMVC.sln b/LearningMVC.sln index df8b3f4..5f6de43 100644 --- a/LearningMVC.sln +++ b/LearningMVC.sln @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControllersAndActions.Tests EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Views", "Views\Views.csproj", "{F99363A1-BC8B-4136-BCC5-87931F1D8899}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkingWithRazor", "WorkingWithRazor\WorkingWithRazor.csproj", "{0F3B5776-589D-4B34-A5F9-86BC8A7F2E63}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,6 +83,10 @@ Global {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 + {0F3B5776-589D-4B34-A5F9-86BC8A7F2E63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F3B5776-589D-4B34-A5F9-86BC8A7F2E63}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F3B5776-589D-4B34-A5F9-86BC8A7F2E63}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F3B5776-589D-4B34-A5F9-86BC8A7F2E63}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WorkingWithRazor/App_Start/RouteConfig.cs b/WorkingWithRazor/App_Start/RouteConfig.cs new file mode 100644 index 0000000..162af0e --- /dev/null +++ b/WorkingWithRazor/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 WorkingWithRazor +{ + 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/WorkingWithRazor/Controllers/HomeController.cs b/WorkingWithRazor/Controllers/HomeController.cs new file mode 100644 index 0000000..b021f10 --- /dev/null +++ b/WorkingWithRazor/Controllers/HomeController.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace WorkingWithRazor.Controllers +{ + public class HomeController : Controller + { + public ActionResult Index() + { + string[] names = { "Apple", "Orange", "Pear" }; + return View(names); + } + + public ActionResult List() + { + return View(); + } + + [ChildActionOnly] + public ActionResult Time() + { + return PartialView(DateTime.Now); + } + } +} \ No newline at end of file diff --git a/WorkingWithRazor/Global.asax b/WorkingWithRazor/Global.asax new file mode 100644 index 0000000..d86c516 --- /dev/null +++ b/WorkingWithRazor/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.cs" Inherits="WorkingWithRazor.MvcApplication" Language="C#" %> diff --git a/WorkingWithRazor/Global.asax.cs b/WorkingWithRazor/Global.asax.cs new file mode 100644 index 0000000..5b85369 --- /dev/null +++ b/WorkingWithRazor/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 WorkingWithRazor.Infrastructure; + +namespace WorkingWithRazor +{ + public class MvcApplication : System.Web.HttpApplication + { + protected void Application_Start() + { + AreaRegistration.RegisterAllAreas(); + RouteConfig.RegisterRoutes(RouteTable.Routes); + + ViewEngines.Engines.Clear(); + ViewEngines.Engines.Add(new CustomLocationViewEngine()); + } + } +} diff --git a/WorkingWithRazor/Infrastructure/CustomLocationViewEngine.cs b/WorkingWithRazor/Infrastructure/CustomLocationViewEngine.cs new file mode 100644 index 0000000..65bb94f --- /dev/null +++ b/WorkingWithRazor/Infrastructure/CustomLocationViewEngine.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace WorkingWithRazor.Infrastructure +{ + public class CustomLocationViewEngine : RazorViewEngine + { + public CustomLocationViewEngine() + { + ViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/Views/Common/{0}.cshtml" }; + } + } +} \ No newline at end of file diff --git a/WorkingWithRazor/Properties/AssemblyInfo.cs b/WorkingWithRazor/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8b4464b --- /dev/null +++ b/WorkingWithRazor/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("WorkingWithRazor")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WorkingWithRazor")] +[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("0f3b5776-589d-4b34-a5f9-86bc8a7f2e63")] + +// 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/WorkingWithRazor/Views/Common/List.cshtml b/WorkingWithRazor/Views/Common/List.cshtml new file mode 100644 index 0000000..69360ee --- /dev/null +++ b/WorkingWithRazor/Views/Common/List.cshtml @@ -0,0 +1,11 @@ +@{ + ViewBag.Title = "List"; + Layout = null; +} + +
The time is: @Model.ToShortTimeString()
diff --git a/WorkingWithRazor/Views/Shared/MyPartial.cshtml b/WorkingWithRazor/Views/Shared/MyPartial.cshtml new file mode 100644 index 0000000..9a74103 --- /dev/null +++ b/WorkingWithRazor/Views/Shared/MyPartial.cshtml @@ -0,0 +1,4 @@ +