HTML-страница с компонентом Blazor отображается хорошо, но когда я нажимаю кнопку, ничего не происходит.< /p>
Я использую Visual Studio 2019 и .NET Core 3.0 и проект ASP.NET MVC.
Counter.razor файл
Код: Выделить всё
@using Microsoft.AspNetCore.Components
Current count: @currentCount
Click me
@code {
int currentCount = 0;
private async Task IncrementCount()
{
await Task.Run(() => currentCount++);
}
}
Код: Выделить всё
@using WebApplication2.Views.Components
@{
ViewData["Title"] = "Home Page";
}
Welcome
Learn about [url=https://learn.microsoft.com/aspnet/core]building Web apps with ASP.NET Core[/url].
@(await Html.RenderComponentAsync(RenderMode.Server, new { }))
Код: Выделить всё
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddHttpClient();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change
// this for production scenarios; see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
Код: Выделить всё
Click me
Ошибка в браузере
Подробнее здесь: https://stackoverflow.com/questions/581 ... -triggered