文本框的 Blazor @onkeypress在 IE 中不起作用?



我正在创建一个服务器端 blazor 应用程序,并具有以下 razor 文件。

@page "/test"
@using BlazorApp2.Data
@inject ViewModels.TestViewModel VM
<div>
Search:
<input id="search" type="text" @bind="VM.Search" @onkeypress="@VM.SearchChanged" />
<span>@VM.Search</span>
</div>

ViewModels.TestViewModel:

public string Search { get; set; }
public async void SearchChanged()
{
// Break point set but not hit?
}

在文本框中键入"搜索"不会在IE中SearchChanged()中设置中断点?它在Chrome中工作。

我想你可能会错过在 Startup.ConfigureServices 中注册 TestViewModel

您可以访问此链接:https://learn.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.0 以参考更多内容。

如果希望 Blazor 在 IE11 上运行,请添加 Polyfill。访问此链接: https://github.com/Daddoon/Blazor.Polyfill 以参考更多。

您可以在此处下载 Polyfills:https://github.com/Daddoon/Blazor.Polyfill/releases

这是您问题之后的示例。希望有帮助,我的朋友:)(

1( 型号

namespace BlazorApp.Models
{
public class TestViewModel
{
public string Search { get; set; }
public async void SearchChanged()
{
// Break point set but not hit?
Search = "Hello world";            
}
}
}

2( 在启动类中

public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddSingleton<Models.TestViewModel>();
}

3(视图

@page "/testview"
@inject Models.TestViewModel VM
<h1>Test Blazor</h1>
<div>
Search:
<input id="search" type="text" @bind="VM.Search" @onkeypress="@VM.SearchChanged" />
<span>@VM.Search</span>
</div>

4( 在_Host视图中

@page "/"
@namespace BlazorApp.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BlazorApp</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
</head>
<body>
<app>
@(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))
</app>
<script src="~/scripts/blazor.polyfill.min.js"></script>
<script src="_framework/blazor.server.js"></script>
</body>
</html>

最新更新