本篇同步发文在个人Blog: 一袋.NET要扛几楼?打造容器化的ASP.NET Core网站!系列文章 - (28) 建立购物车系统 - 11
在网站登入後,要增加购物车Cart ViewComponent,需修改_LoginPartial.cshtml:
@using WebMvc.Services
@inject IAuthService<ApplicationUser> UserManager
@if (User?.Identity?.IsAuthenticated == true)
{
<li>
@User.FindFirst(x => x.Type == "preferred_username").Value
</li>
<li>
@await Component.InvokeAsync("Cart", new { user = UserManager.Get(User) })
</li>
<li class="pull-right">
<form asp-area="" asp-controller="Account" asp-action="SignOut" method="post" id="logoutForm">
<a href="javascript:document.getElementById('logoutForm').submit()">
Log Out
</a>
</form>
</li>
}
else
{
<li>
<a asp-area="" asp-controller="Account" asp-action="SignIn">
Login
</a>
</li>
}
在Views/Shared的目录,新增Components目录,再新增Cart目录,最後加上Default.cshtml,也就是之前继承ViewComponent的Cart.cs会回传的页面,主要是显示购物车的数量:
@model WebMvc.ViewModels.CartComponentViewModel
@{
ViewData["Title"] = "My Cart";
}
<a class="@Model.Disabled" asp-area="" asp-controller="Cart" asp-action="Index">
@if (ViewBag.IsCartInoperative == true)
{
<p class="fa fa-2x fa-shopping-cart">X</p>
}
else
{
<p class="fa fa-2x fa-shopping-cart">@Model.ItemsInCart</p>
}
</a>
<<: [Day29] 部署网站 - 我与 ASP.NET Core 3 的 30天
>>: [Day 28] 社会对人工智慧的期待与影响 Society Concern and Impact
第 25 天 ! 我们知道 redux 结构 flux-like , 那麽他的每个阶段是在处理什麽?...
关於SEC的事情 资料库演练100%备份还原 每年至少两次的资料灾害恢复演练,资料要100%覆盖,要...
於今年一月份毕业,在大学学了作业系统、资料结构、演算法、JAVA 程序语言...,但我从没想过要如何...
接着我们要利用PGADMIN连线我们Heroku上的资料库插件 打开PGADMIN,输入昨天输入的密...
下载完VSCode之後 Part1 : 我们可以在延伸模组的地方搜寻并安装你所需要的模组 Part2...