ASP.NET Core是一个用于构建Web和云应用程序的精简,可组合和跨平台的框架。它是GitHub上完全开源的。 ASP.NET核心应用程序可以在Windows上运行完整的.NET Framework或更小的.NET Core,也可以在Linux和MacOS上运行.NET Core和Mono。
使用 .NET 8.0 构建时无法解析“net6.0”的“Microsoft.NETCore.App.Ref (= 6.0.27)”
我在尝试使用 .NET8 构建项目时收到以下错误。 错误 NU1100:无法解析“net6.0”的“Microsoft.NETCore.App.Ref (= 6.0.27)”。 机器没有网络
我从一家托管公司购买了托管,然后我了解到我只能在我的托管上运行一个 ASP.NET 项目。我可以在一个 ASP.NET 项目中创建多个 ASP.NET 应用程序吗? 所以我的意思是...
尝试通过 Vite 开发服务器向 ASP.NET 项目提供文件时出现 React Preamble 错误
我正在尝试使用 ClientApp 设置 ASP.NET MVC 应用程序,该 ClientApp 使用 React 和 Vite 作为捆绑器。这应该是 MPA 而不是 SPA,所以 每个ac都会有一个单独的.tsx文件...
ASP.NET Core 6 应用程序部件项目必须引用哪些 Nuget 包
我正在创建一个 ASP.NET Core 6 应用程序,我想在其中集成由单独程序集提供的其他区域。我遵循 https://learn.microsoft.com/en-us/aspnet/cor... 的文档...
如何从代码调用 REST API,我只得到 AuthenticationException、UntrustedRoot
我对 REST 服务相当陌生,我正在尝试从同事那里调用 REST 服务,仅通过用户名和密码进行保护。 使用 Postman 一切都很好,我有一个 GET 到 URL,我选择 ...
NavLink 更新 URL,但不会在 Blazor 中重新加载页面
我有一个 ProjectBase.razor 页面,用于创建、查看和编辑项目。以下路线均可将您带到此页面: /项目/视图/{projNum} /项目/创建/ /项目/编辑/{projNum} 我
我正在尝试使用滑块进行价格过滤。景色将会是这样的。我使用ajax来填充价格。这是滑块和产品视图的代码: 我正在尝试使用滑块进行价格过滤。看到的景色会是这样的。我使用ajax来填充价格。这是滑块和产品视图的代码: <div class="price-filter"> <div id="price-slider"></div> <div class="input-number price-min"> <input id="price-min" type="number"> <span class="qty-up">+</span> <span class="qty-down">-</span> </div> <span>-</span> <div class="input-number price-max"> <input id="price-max" type="number"> <span class="qty-up">+</span> <span class="qty-down">-</span> </div> </div> //product <div id="store" class="col-md-9"> <div class="row"> <!-- product --> @foreach (var item in Model.Take(6)) { <div class="col-md-4 col-xs-6"> <div class="product"> <a href="/post/@SlugGenerator.SlugGenerator.GenerateSlug(item.ProductName)[email protected]().ProductVariations.FirstOrDefault().ProductVarId" /> <div class="product-img"> <img src="~/Contents/img/@item.ProductItems.FirstOrDefault().Image1" width="200" height="200" alt=""> <div class="product-label"> <span class="sale">-30%</span> <span class="new">NEW</span> </div> </div> <div class="product-body"> @* <p class="product-category">@item.Category.CategoryName.ToUpper()</p> *@ <h3 class="product-name"><a href="#">@item.ProductName.ToUpper()</a></h3> <h4 class="product-price">[email protected]<del class="product-old-price">@* $@(item.Product.Price + 200) *@</del></h4> <div class="product-rating"> <i class="fa fa-star"></i> <i class="fa fa-star"></i> <i class="fa fa-star"></i> <i class="fa fa-star"></i> <i class="fa fa-star"></i> </div> <div class="product-btns"> <button class="add-to-wishlist"><i class="fa fa-heart-o"></i><span class="tooltipp">add to wishlist</span></button> <button class="add-to-compare"><i class="fa fa-exchange"></i><span class="tooltipp">add to compare</span></button> <button class="quick-view"><i class="fa fa-eye"></i><span class="tooltipp">quick view</span></button> </div> </div> </div> </div> } <!-- /product --> </div> </div> ajax 代码,因此可以按价格过滤产品,而无需重新加载页面: <script> $(function () { $("#price-slider").slider({ range: true, min: 100000, max: 2000000, values: [100000, 2000000], slide: function (event, ui) { $("#price-min").val(ui.values[0]); $("#price-max").val(ui.values[1]); }, stop: function (event, ui) { var min = ui.values[0]; var max = ui.values[1]; var cateid = $('#category-id').val(); $.ajax({ url: '@Url.Action("FilterByPrice", "ProductView")', type: 'GET', data: { minPrice: min, maxPrice: max, categoryId: cateid }, success: function (productlist) { var newproductrow = ""; $.each(productlist, function (index, item) { newproductrow += '<div class="col-md-4 col-xs-6">'; newproductrow += '<div class="product">'; newproductrow += '<a href="/post/' + item.SlugGenerator.SlugGenerator.GenerateSlug(item.ProductName) + '-' + item.ProductItems[0].ProductVariations[0].ProductVarId + '">'; newproductrow += '<div class="product-img">'; newproductrow += '<img src="~/Contents/img/' + item.ProductItems[0].Image1 + '" width="200" height="200" alt="">'; newproductrow += '<div class="product-label">'; newproductrow += '<span class="sale">-30%</span>'; newproductrow += '<span class="new">NEW</span>'; newproductrow += '</div>'; // Close product-label newproductrow += '</div>'; // Close product-img newproductrow += '<div class="product-body">'; newproductrow += '<h3 class="product-name"><a href="#">' + item.ProductName.toUpperCase() + '</a></h3>'; newproductrow += '<h4 class="product-price">$' + item.Price + '<del class="product-old-price">$' + (item.Price + 200) + '</del></h4>'; newproductrow += '<div class="product-rating">'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '</div>'; // Close product-rating newproductrow += '<div class="product-btns">'; newproductrow += '<button class="add-to-wishlist"><i class="fa fa-heart-o"></i><span class="tooltipp">add to wishlist</span></button>'; newproductrow += '<button class="add-to-compare"><i class="fa fa-exchange"></i><span class="tooltipp">add to compare</span></button>'; newproductrow += '<button class="quick-view"><i class="fa fa-eye"></i><span class="tooltipp">quick view</span></button>'; newproductrow += '</div>'; // Close product-btns newproductrow += '</div>'; // Close product-body newproductrow += '</div>'; // Close product newproductrow += '</div>'; // Close col-md-4 }); $("#store .row").html(newproductrow); } }); } }); }); </script> 控制器过滤价格: [HttpGet] public IActionResult FilterByPrice(int minPrice, int maxPrice, int categoryId) { var filteredProducts = _context.Products .Where(p => p.Price >= minPrice && p.Price <= maxPrice && p.CategoryId == categoryId) .ToList(); return new JsonResult(filteredProducts); } 但是当我调整那个栏时,什么也没有发生。我打开网络并选择Fetch/XHR,当我调整栏时,我看到有一个json返回。 json 返回: { "$id": "1", "$values": [ { "$id": "2", "productId": 8, "productName": "POSEE", "categoryId": 4, "price": 400000, "description": null, "brand": 5, "brandNavigation": null, "category": null, "productItems": { "$id": "3", "$values": [] } }, { "$id": "4", "productId": 9, "productName": "ShondoHCM", "categoryId": 4, "price": 500000, "description": null, "brand": 11, "brandNavigation": null, "category": null, "productItems": { "$id": "5", "$values": [] } }, { "$id": "6", "productId": 10, "productName": "BITIS", "categoryId": 4, "price": 800000, "description": null, "brand": 4, "brandNavigation": null, "category": null, "productItems": { "$id": "7", "$values": [] } } ] } 有人知道为什么产品不按价格显示的问题吗?我相信这是关于 for 循环的。我真的很感谢任何指导。谢谢你 该错误很可能是因为您在 jQuery 代码中使用 PascalCase 属性,并且以驼峰命名法接收 JSON。要修复它,请将脚本更改为: <script> $(function () { $("#price-slider").slider({ range: true, min: 100000, max: 2000000, values: [100000, 2000000], slide: function (event, ui) { $("#price-min").val(ui.values[0]); $("#price-max").val(ui.values[1]); }, stop: function (event, ui) { var min = ui.values[0]; var max = ui.values[1]; var cateid = $('#category-id').val(); $.ajax({ url: '@Url.Action("FilterByPrice", "ProductView")', type: 'GET', data: { minPrice: min, maxPrice: max, categoryId: cateid }, success: function (productlist) { var newproductrow = ""; $.each(productlist, function (index, item) { newproductrow += '<div class="col-md-4 col-xs-6">'; newproductrow += '<div class="product">'; newproductrow += '<a href="/post/' + item.SlugGenerator.SlugGenerator.GenerateSlug(item.productName) + '-' + item.productItems[0].productVariations[0].productVarId + '">'; newproductrow += '<div class="product-img">'; newproductrow += '<img src="~/Contents/img/' + item.productItems[0].image1 + '" width="200" height="200" alt="">'; newproductrow += '<div class="product-label">'; newproductrow += '<span class="sale">-30%</span>'; newproductrow += '<span class="new">NEW</span>'; newproductrow += '</div>'; // Close product-label newproductrow += '</div>'; // Close product-img newproductrow += '<div class="product-body">'; newproductrow += '<h3 class="product-name"><a href="#">' + item.productName.toUpperCase() + '</a></h3>'; newproductrow += '<h4 class="product-price">$' + item.price + '<del class="product-old-price">$' + (item.price + 200) + '</del></h4>'; newproductrow += '<div class="product-rating">'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '<i class="fa fa-star"></i>'; newproductrow += '</div>'; // Close product-rating newproductrow += '<div class="product-btns">'; newproductrow += '<button class="add-to-wishlist"><i class="fa fa-heart-o"></i><span class="tooltipp">add to wishlist</span></button>'; newproductrow += '<button class="add-to-compare"><i class="fa fa-exchange"></i><span class="tooltipp">add to compare</span></button>'; newproductrow += '<button class="quick-view"><i class="fa fa-eye"></i><span class="tooltipp">quick view</span></button>'; newproductrow += '</div>'; // Close product-btns newproductrow += '</div>'; // Close product-body newproductrow += '</div>'; // Close product newproductrow += '</div>'; // Close col-md-4 }); $("#store .row").html(newproductrow); } }); } }); }); 此行也会抛出错误: newproductrow += '<a href="/post/' + item.SlugGenerator.SlugGenerator.GenerateSlug(item.productName) + '-' + item.productItems[0].productVariations[0].productVarId + '">'; 最好在后端调用SlugGenerator.GenerateSlug,如下所示: [HttpGet] 公共异步任务 FilterByPrice(int minPrice, int maxPrice, int CategoryId) { var filteredProducts = await _context.Products .Where(p => p.Price >= minPrice && p.Price <= maxPrice && p.CategoryId == categoryId) .Select(m => new ProductView { Brand = m.Brand, BrandNavigation = m.BrandNavigation, Category = m.Category, CategoryId = categoryId, Description = m.Description, Id = m.Id, Price = m.Price, ProductId = m.ProductId, ProductItems = m.ProductItems, ProductName = m.ProductName, //Here to generate SlugName using SlugGenerator (Note that method must be static) SlugName = Item.SlugGenerator.GenerateSlug(m.ProductName), }) .ToListAsync(); return new JsonResult(filteredProducts); } 并在 jQuery 中将该行更改为 newproductrow += '<a href="/post/' + item.slugName + '">';
我正在尝试设置一个实验性的 C# 8 服务器,它可以运行 Web API、Razor 页面,还可以运行特定路径(例如“/spa1”)的各种 React 应用程序,但无法让 SPA 运行一个
使用 NUnit 和 NSubstitute 进行单元测试中间件
我在 ASP.NET Core 站点中编写了一些中间件,我正在尝试对其进行单元测试,主要是遵循本使用 Moq 的指南。 我的问题是找到一个与 new
ASP.NET Core - 尝试使用 HealthChecks 时出错
我正在尝试使用 .NET Core 2.2 运行状况检查。 在ConfigureServices 中,我注册了实现Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck 接口的类。 但当我
如何在 ASP.NET Core 8 中根据登录用户设置 Cookie 和会话超时
我设置cookie和会话超时如下(我需要使用这个API。我不能使用新的Identity api): .AddCookie(选项=> { options.ExpireTimeSpan = TimeSpan.FromMinutes(15);
我正在使用 Logger 来记录我的 Web 应用程序中的错误。它在我的开发机器中完美运行,但在发布时却无法运行。 此错误记录在事件日志中(使用应用程序源): 无法...
使用方法代码在 ASP.NET Core Web API 中创建文件夹 wwroot
我正在为我的 Web 应用程序的背面开发 ASP.NET Core Web API,前面是 Angular。我需要在我的服务器中保存图像或 PDF 等内容并访问它们,所以我想将这些文件保存在...
范围后台服务对于基于客户端请求的长时间运行任务来说是不错的选择吗?
我正在构建一个 ASP.NET Core 应用程序,需要通过 SignalR 中心管理由客户端请求启动的长时间运行的任务(任务运行直到客户端关闭浏览器或检测到交互性)。我
在Asp.Net Core MVC,AppSettings.json中,如何从静态类中获取值
我有一个使用 Visual Studio 2022 的新项目,使用 .Net 8.0(核心)使用 asp.net MVC。 在 AppSettings.json 中,我有一个连接字符串。 “连接字符串”:{ “MyDB”:&qu...
我正在致力于将 Identity 集成到我的 .NET Core 8.0 应用程序中并实现 JWT Bearer 身份验证。但是,我遇到了错误 System.InvalidOperationException:方案已经
如何在 razor 组件中使用 Blazor .NET 8 生成身份验证器二维码
使用 .NET 8 中的新 Identity razor 组件时,您仍然可以获得本文的链接:https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-enable-qrcodes ?查看=
C# .NET Core Worker 服务需要根据设置记录到文本文件和数据库表
我添加了用于写入文本文件的 Serilog 和用于写入 SQL Server 数据库表的自定义提供程序。当我添加任何一个时,该代码都有效,但如果同时添加两者,则仅 Serilog 有效。请指教
如何在ConfigureServices方法中获取IOptions?
我有asp.net core应用程序。我想使用 IOptions 模式从 appsettings.json 注入值。所以我有一个类 SecurityHeaderOptions,并且还有目标类 SecurityHeadersBuilder wh...
当EditForm有OnValidSubmit时所有值都会重置
我有一个 Blazor 组件。传入 Id,但当编辑表单的 OnValidSubmit 首先触发时,它会按预期运行“OnInitializedAsync()”。 我首先在页面加载时将参数设置为 true...