У меня есть .razor и соответствующий .razor.cs.
При нажатии на ссылку a SelectSort не активируется.
Я пробовал используя @rendermode InteractiveServer, который обновляет currentSort при изменении текста раскрывающегося списка, но не влияет на dtProducts. Добавление этого также нарушает работу других функций на странице, поскольку они проявляют те же симптомы: код переходит к соответствующим функциям при нажатии, но функция, похоже, не оказывает никакого влияния на состояние пользовательского интерфейса.
@page "/c"
@page "/c/{id}"
@using System.Data
...
@(currentSort ?? "Sort results")
Recommended
Price - Low to High
Price - High to Low
@foreach (DataRow row in dtProducts.Rows)
{
...
}
В формате .cs:
private async Task SelectSort(string sColumn)
{
Console.WriteLine("Sorting by: " + sColumn);
currentSort = sColumn;
if (dtProducts != null)
{
DataView dv = dtProducts.DefaultView;
dv.Sort = sColumn;
dtProducts = dv.ToTable();
}
StateHasChanged();
}
Program.cs
using barx.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using barx;
using Microsoft.AspNetCore.Authentication.Cookies;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddHttpContextAccessor(); // Add this line
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/admin/login";
options.LogoutPath = "/admin/logout";
options.AccessDeniedPath = "/admin/login";
});
builder.Services.AddAuthorization();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped();
builder.Services.AddScoped();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
SVG.Initialize(builder.Environment);
app.UseHttpsRedirection();
app.UseStaticFiles();
// Make sure UseAuthentication and UseAuthorization come before MapRazorComponents
app.UseAuthentication();
app.UseAuthorization();
app.UseAntiforgery();
app.MapRazorComponents()
.AddInteractiveServerRenderMode();
app.Run();
Подробнее здесь: https://stackoverflow.com/questions/790 ... -functions