我正在创建服务器端的blazor应用程序,并具有以下剃刀文件。
@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://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.0以了解更多。
[如果您希望Blazor在IE11上运行,请添加Polyfills。访问此链接: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>