Adding a view component for cart summary
1. Added a View component named CartSummary 2. Moved the CartSummary.cshtml as default.cshtml to shared\Components
This commit is contained in:
parent
58d4b48690
commit
b51f54e98a
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
|
using MusicStore.Models;
|
||||||
|
|
||||||
|
namespace MusicStore.Components
|
||||||
|
{
|
||||||
|
[ViewComponent(Name = "CartSummary")]
|
||||||
|
public class CartSummaryComponent : ViewComponent
|
||||||
|
{
|
||||||
|
private MusicStoreContext db = new MusicStoreContext();
|
||||||
|
public async Task<IViewComponentResult> InvokeAsync()
|
||||||
|
{
|
||||||
|
var cart = ShoppingCart.GetCart(db, this.Context);
|
||||||
|
|
||||||
|
var cartItems = cart.GetCartItems()
|
||||||
|
.Select(a => a.Album.Title)
|
||||||
|
.OrderBy(x => x);
|
||||||
|
|
||||||
|
//Bug: Uncommenting results in compilation error.
|
||||||
|
//ViewBag.CartCount = cartItems.Count();
|
||||||
|
//ViewBag.CartSummary = string.Join("\n", cartItems.Distinct());
|
||||||
|
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,8 +27,7 @@
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li>@Html.ActionLink("Home", "Index", "Home")</li>
|
<li>@Html.ActionLink("Home", "Index", "Home")</li>
|
||||||
@await Component.InvokeAsync("GenreMenu")
|
@await Component.InvokeAsync("GenreMenu")
|
||||||
@*Bug: HtmlHelper missing*@
|
@*@await Component.InvokeAsync("CartSummary")*@
|
||||||
@*@Html.Action("CartSummary", "ShoppingCart")*@
|
|
||||||
</ul>
|
</ul>
|
||||||
@await Html.PartialAsync("_LoginPartial")
|
@await Html.PartialAsync("_LoginPartial")
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue