我使用复选框进行数据过滤。我希望当我单击“提交”按钮时,仅更新产品而不重新加载页面
\n这是过滤:
\n<form id="my_form" asp-action="Face" method="get">\n <label>Color:</label>\n <input type="checkbox" name="color" value="black" /><span>Black</span>\n <input type="checkbox" name="color" value="white" /><span>White</span>\n <br />\n <p></p>\n <label>Manufacturer:</label>\n <input type="checkbox" name="brand" value="A" /><span>A</span>\n <input type="checkbox" name="brand" value="B" /><span>B</span>\n <input class="btn btn-info float-right" type="submit" value="Search" />\n //Etc\n</form>\nRun Code Online (Sandbox Code Playgroud)\n我需要先显示这些数据。在通过过滤器的情况下,它们会根据我传递给控制器的内容进行更新
\n <div class="row pr-3 pl-3">\n @foreach (var c in Model)\n {\n <div class="filter col-md-3 p-0 hover-bc-card" data-category="@c.PurposeFor">\n <div class="p-3">\n <a class="text-decoration-none text-dark" asp-action="Product" asp-controller="Cosmetic" asp-route-id="@c.Id">\n <div>\n <img class="card-img-top p-4 bg-white" src=@c.Img alt="@c.Name">\n </div>\n </a>\n <div class="card-body">\n <h5 …Run Code Online (Sandbox Code Playgroud) 我需要从控制器将一些值传递给视图组件。我尝试了不同的方法,但它没有传输。如果我不将任何内容传递给构造函数,那么一切都会正常工作,但是当我尝试将其传递给构造函数时,它甚至不会调用 ViewComponent
控制器:
[HttpGet]
public IActionResult AddToCart(int id)
{
return ViewComponent("Cart", new {id});
}
Run Code Online (Sandbox Code Playgroud)
查看组件:
public class CartViewComponent : Microsoft.AspNetCore.Mvc.ViewComponent
{
int gId;
public CartViewComponent(int id)
{
gId = id;
}
public IViewComponentResult Invoke()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)