[英]Blazor @onkeypress of a text box doesn't work in IE?
I'm creating a server-side blazor application and have the following razor file.我正在创建一个服务器端 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: ViewModels.TestViewModel:
public string Search { get; set; }
public async void SearchChanged()
{
// Break point set but not hit?
}
Typing in the text box "search" doesn't hit the break point set in SearchChanged()
when in IE?在 IE 中键入“搜索”文本框不会达到
SearchChanged()
中设置的断点? It works in Chrome.它适用于 Chrome。
I think you can miss registering TestViewModel in Startup.ConfigureServices我认为您可能会错过在 Startup.ConfigureServices 中注册 TestViewModel
You can visit this link: https://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.0 to refer more.您可以访问此链接: https://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.0以参考更多信息。
If you want Blazor run on IE11, please add Polyfills.如果您希望 Blazor 在 IE11 上运行,请添加 Polyfills。 Visit this link: https://github.com/Daddoon/Blazor.Polyfill to refer more.
访问此链接: https://github.com/Daddoon/Blazor.Polyfill以参考更多信息。
You can download Polyfills at here: https://github.com/Daddoon/Blazor.Polyfill/releases你可以在这里下载 Polyfills: https://github.com/Daddoon/Blazor.Polyfill/releases
Here is a sample following your question.这是您的问题之后的示例。 Hope to help, my friend:))
希望对你有所帮助,我的朋友:))
1) Models 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) In Startup class 2) 在启动 class
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddSingleton<Models.TestViewModel>();
}
3)View 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) In _Host view 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.