Why don't TagHelpers?

Study ASP.NET CORE MVC.
Version .net core 2.1.402.

Case study: the Internet shop.
When you click on the "Add" button product should added to cart and you should now see the shopping cart page.

In the project there is a folder "Views", it has:
Product\List.cshtml
@model ProductsListViewModel

@foreach (var p in Model.Products)
{
 @Html.Partial("_ProductSummary", p)
}

Shared\_Layout.cshtml
<!DOCTYPE html>

<html>
the <head>
 <meta name="viewport" content="width=device-width" />
<title>Shop</title>
</head>
the <body>
@RenderBody()
</body>
</html>

Shared\_ProductSummary.cshtml
@model Product

the <div>
the <div>
the <div>@Model.Name</div>
 the <div>@Model.Price.ToString("c", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))<div>
the <div>@Model.Description</div>
the <div>
 <form id="@Model.ProductID" asp-action="AddToCart" asp-controller="Cart" method="post">
 <input type="hidden" asp-for="ProductID" />
 <input type="hidden" name="returnUrl" value="@ViewContext.HttpContext.Request.PathAndQuery()" />
 <button type="submit">Add</button>
</form>
</div>

_ViewStart.cshtml
@{
 Layout = "_Layout";
}

_ViewImports.cshtml
@using Store.Models
@using Store.Models.ViewModels
@using Store.Infrastructure
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper Store.Infrastructure.*, Store

Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Store.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;

namespace Store
{
 public class Startup
{
 string _ContentRootPath;

 IConfigurationRoot Configuration;

 public Startup(IHostingEnvironment env)
{
 _ContentRootPath = env.ContentRootPath;

 Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.Build();
}

 public void ConfigureServices(IServiceCollection services)
{
 services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(Configuration["Data:StoreProducts:ConnectionString"]));
 services.AddTransient<IProductRepository, EFProductRepository>();
 services.AddScoped<Cart>(sp => SessionCart.GetCart(sp));
 services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddMvc();
services.AddMemoryCache();
services.AddSession();
}

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseSession();
app.UseMvc(routes=>
{
routes.MapRoute(
name:null,
template:"{category}/Page{page:int}",
 defaults:new {controller="Product", action="List"}
);

routes.MapRoute(
name:null,
template:"Page{page:int}",
 defaults:new {controller="Product", action="List", page = 1}
);

routes.MapRoute(
name:null,
template:"{category}",
 defaults:new {controller="Product", action="List", page = 1}
);

routes.MapRoute(
name:null,
 template: "",
 defaults:new {controller="Product", action="List", page = 1}
);

routes.MapRoute(
 name: null,
 template: "{controller}/{action}/{id?}"
);

});


SeedData.EnsurePopulated(app);
}
}
}


By default, we have displayed Product\List, which is formed from a partial view (@Html.Partial) _ProductSummary. _ProdictSummary contains a different data item and the form with the "Add" button. When you click on the "Add" button would be a POST request, which should start AddToCart action method of a controller of the Cart basket which will add goods to the shopping list and display the performance of the basket.

In fact the "Add" button is not working. Saw that in the HTML Product\List in the form does not work TagHelper's. Ie where is asp-action="AddToCart" should appear action=/Cart/AddToCart still asp-action="AddToCart". And other asp-xxx (asp-controller and asp-for) is also not "unfold". At least I understand what they are supposed to work.

Why don't TagHelper's? How to fix?
March 12th 20 at 07:58
0 answer

Find more questions by tags ASP.NET