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; +} + +

This is the /Views/Common/List.cshtml View

+ +@*@Html.Partial("MyPartial")*@ +@Html.Partial("MyStronglyTypedPartial", new [] { "Apple", "Orange", "Pear"}) + +@Html.Action("TIME") \ No newline at end of file diff --git a/WorkingWithRazor/Views/Home/Index.cshtml b/WorkingWithRazor/Views/Home/Index.cshtml new file mode 100644 index 0000000..b16f7ac --- /dev/null +++ b/WorkingWithRazor/Views/Home/Index.cshtml @@ -0,0 +1,32 @@ +@model string[] +@{ + ViewBag.Title = "Index"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +@section Header { +
+ @foreach (string str in new[] { "Home", "List", "Edit" }) + { + @Html.ActionLink(str, str, null, new { style = "margin: 5px" }) + } +
+} + +@section Body { +
+ This is a list of fruit names: + + @foreach (string name in Model) + { + @name +

+ } +

+} + +@section Footer{ +
+ This is the footer +
+} \ No newline at end of file diff --git a/WorkingWithRazor/Views/Home/Time.cshtml b/WorkingWithRazor/Views/Home/Time.cshtml new file mode 100644 index 0000000..f6722f8 --- /dev/null +++ b/WorkingWithRazor/Views/Home/Time.cshtml @@ -0,0 +1,3 @@ +@model DateTime + +

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 @@ +
+ This is the message from the partial view. + @Html.ActionLink("This is a link to the Index action", "Index") +
diff --git a/WorkingWithRazor/Views/Shared/MyStronglyTypedPartial.cshtml b/WorkingWithRazor/Views/Shared/MyStronglyTypedPartial.cshtml new file mode 100644 index 0000000..2cb3ff4 --- /dev/null +++ b/WorkingWithRazor/Views/Shared/MyStronglyTypedPartial.cshtml @@ -0,0 +1,10 @@ +@model IEnumerable +
+ This is the message from the partial view + +
\ No newline at end of file diff --git a/WorkingWithRazor/Views/Shared/_Layout.cshtml b/WorkingWithRazor/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..13b7d22 --- /dev/null +++ b/WorkingWithRazor/Views/Shared/_Layout.cshtml @@ -0,0 +1,32 @@ + + + + + + + + @ViewBag.Title + + + @RenderSection("Header") +
+ This is part of the layout +
+ + @RenderSection("Body") +
+ This is part of the layout +
+ + @RenderSection("Footer") + +
+ This is part of the layout +
+ + @RenderSection("scripts", false) + + diff --git a/WorkingWithRazor/Views/web.config b/WorkingWithRazor/Views/web.config new file mode 100644 index 0000000..714b2cf --- /dev/null +++ b/WorkingWithRazor/Views/web.config @@ -0,0 +1,42 @@ + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WorkingWithRazor/Web.Debug.config b/WorkingWithRazor/Web.Debug.config new file mode 100644 index 0000000..fae9cfe --- /dev/null +++ b/WorkingWithRazor/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/WorkingWithRazor/Web.Release.config b/WorkingWithRazor/Web.Release.config new file mode 100644 index 0000000..da6e960 --- /dev/null +++ b/WorkingWithRazor/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/WorkingWithRazor/Web.config b/WorkingWithRazor/Web.config new file mode 100644 index 0000000..43634a3 --- /dev/null +++ b/WorkingWithRazor/Web.config @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WorkingWithRazor/WorkingWithRazor.csproj b/WorkingWithRazor/WorkingWithRazor.csproj new file mode 100644 index 0000000..19622b8 --- /dev/null +++ b/WorkingWithRazor/WorkingWithRazor.csproj @@ -0,0 +1,162 @@ + + + + + + Debug + AnyCPU + + + 2.0 + {0F3B5776-589D-4B34-A5F9-86BC8A7F2E63} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + WorkingWithRazor + WorkingWithRazor + 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 + 7490 + / + http://localhost:7490/ + 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/WorkingWithRazor/packages.config b/WorkingWithRazor/packages.config new file mode 100644 index 0000000..262d240 --- /dev/null +++ b/WorkingWithRazor/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file