Skip to content

Commit

Permalink
Moving the footer section to a new view component
Browse files Browse the repository at this point in the history
  • Loading branch information
gorohoroh committed Jul 12, 2018
1 parent 7c2db66 commit d1e4e4a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using OdeToFoodRider.Services;

namespace OdeToFoodRider.ViewComponents
{
public class GreeterViewComponent : ViewComponent
{
private readonly IGreeter _greeter;

public GreeterViewComponent(IGreeter greeter)
{
_greeter = greeter;
}

public IViewComponentResult Invoke()
{
var model = _greeter.GetMessageOfTheDay();
return View("Default", model);
}
}
}
5 changes: 0 additions & 5 deletions OdeToFoodRider/OdeToFoodRider/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@
}

<div ><a asp-action="Create">Add Restaurant</a></div>

@section footer
{
@Model.CurrentMessage
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@model string

<div>
@Model
</div>
6 changes: 5 additions & 1 deletion OdeToFoodRider/OdeToFoodRider/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<div>
@RenderBody()
</div>
<footer>@RenderSection("footer", required: false)</footer>
<footer>
@RenderSection("footer", required: false)
@await Component.InvokeAsync("Greeter")
<vc:greeter></vc:greeter>
</footer>
</body>
</html>
2 changes: 1 addition & 1 deletion OdeToFoodRider/OdeToFoodRider/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using OdeToFoodRider.Models
@using OdeToFoodRider.ViewModels
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@* VSRD: No completion suggestions for assembly name in Rider, too :( - completion for @addTagHelper is available though *@
@addTagHelper *, OdeToFoodRider
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using OdeToFoodVisualStudio.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OdeToFoodVisualStudio.ViewComponents
{
public class GreeterViewComponent : ViewComponent
{
private IGreeter _greeter;

public GreeterViewComponent(IGreeter greeter)
{
_greeter = greeter;
}

public IViewComponentResult Invoke()
{
var model = _greeter.GetMessageOfTheDay();
return View("Default", model);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@
<div>
<a asp-action="Create">Add Restaurant</a>
</div>

@section footer {
@Model.CurrentMessage
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@model string

<div>
@Model
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<div>
@RenderBody()
</div>
<footer>@RenderSection("footer", required: false)</footer>
<footer>
@RenderSection("footer", required: false)
@await Component.InvokeAsync("Greeter")
<vc:greeter></vc:greeter>
</footer>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using OdeToFoodVisualStudio.Models;
@using OdeToFoodVisualStudio.ViewModels;
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, OdeToFoodVisualStudio
@* VSRD: Visual Studio provides no completion for the assembly name above *@

0 comments on commit d1e4e4a

Please sign in to comment.