From 622e61cef13a5c6043784abffb0bfa0d5406f3d3 Mon Sep 17 00:00:00 2001 From: gorohoroh Date: Fri, 6 Jul 2018 19:50:00 +0300 Subject: [PATCH] Creating a layout view and using it from the index view --- .../OdeToFoodRider/Views/Home/Index.cshtml | 18 +++---- .../Views/Shared/_Layout.cshtml | 13 +++++ .../Views/Home/Index.cshtml | 50 +++++++++---------- .../Views/Shared/_Layout.cshtml | 14 ++++++ 4 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 OdeToFoodRider/OdeToFoodRider/Views/Shared/_Layout.cshtml create mode 100644 OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Shared/_Layout.cshtml diff --git a/OdeToFoodRider/OdeToFoodRider/Views/Home/Index.cshtml b/OdeToFoodRider/OdeToFoodRider/Views/Home/Index.cshtml index 645d9b1..0327798 100644 --- a/OdeToFoodRider/OdeToFoodRider/Views/Home/Index.cshtml +++ b/OdeToFoodRider/OdeToFoodRider/Views/Home/Index.cshtml @@ -1,14 +1,12 @@ @using OdeToFoodRider.Models @model OdeToFoodRider.ViewModels.HomeIndexViewModel - +@{ + ViewBag.Title = "Home page"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} - - - My title - - -

@Model.CurrentMessage

+

All Restaurants

@* VSRD: No table snippet in Rider. *@ @* VSRD: No foreach live template here, just keyword completion like in Visual Studio *@ @@ -29,5 +27,7 @@ Add Restaurant - - +@section footer +{ + @Model.CurrentMessage +} diff --git a/OdeToFoodRider/OdeToFoodRider/Views/Shared/_Layout.cshtml b/OdeToFoodRider/OdeToFoodRider/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..0236aa5 --- /dev/null +++ b/OdeToFoodRider/OdeToFoodRider/Views/Shared/_Layout.cshtml @@ -0,0 +1,13 @@ + + + + + @ViewBag.Title + + +
+ @RenderBody() +
+ + + \ No newline at end of file diff --git a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Home/Index.cshtml b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Home/Index.cshtml index a387f7b..1b9939f 100644 --- a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Home/Index.cshtml +++ b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Home/Index.cshtml @@ -1,29 +1,29 @@ @* VSRD: Visual Studio doesn't suggest importing the Restaurant model when typing @model Restaurant, so you have to type in the FQN. Let's see what Rider can do here :) *@ @model OdeToFoodVisualStudio.ViewModels.HomeIndexViewModel - - - - - +@{ ViewBag.Title = "Home page"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} -

@Model.CurrentMessage

- @* VSRD: Table generated in VS with a "table" code snippet *@ -
- @* VSRD: No 'foreach' code snippet in VS, just keyword completion *@ - @foreach (var restaurant in Model.Restaurants) - { - - - - - - } -
@restaurant.Id@restaurant.Name - Details - @Html.ActionLink("Go", "Details", new { id = restaurant.Id }) - More -
- Add Restaurant - - \ No newline at end of file +

All Restaurants

+@* VSRD: Table generated in VS with a "table" code snippet *@ + + @* VSRD: No 'foreach' code snippet in VS, just keyword completion *@ + @foreach (var restaurant in Model.Restaurants) + { + + + + + + } +
@restaurant.Id@restaurant.Name + Details + @Html.ActionLink("Go", "Details", new { id = restaurant.Id }) + More +
+Add Restaurant + +@section footer { + @Model.CurrentMessage +} \ No newline at end of file diff --git a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Shared/_Layout.cshtml b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..216f509 --- /dev/null +++ b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Views/Shared/_Layout.cshtml @@ -0,0 +1,14 @@ + + + + + + @ViewBag.Title + + +
+ @RenderBody() +
+ + +