我在客户端 Blazor Web 应用程序中遇到 AmbigouslyMatchException 错误。错误消息显示“请求与多个端点匹配。匹配:后备 {*path:nonfile}”。我尝试添加包含此行的 app.razor
<body>
<div id="app"></div>
</body>
修复它,但没有成功。我还添加了 builder.RootComponents.Add("#app");到program.cs但仍然无法解决它。谁能帮我解决这个问题?这是我尝试调用的页面:
@page "/add-Product"
<div class="container">
<div class="row">
<div class="col-md-6">
<EditForm Model="MyProduct" Enhance OnInvalidSubmit="HandleSaveProduct" >
<DataAnnotationsValidator/>
<ValidationSummary></ValidationSummary>
<div class="card">
<div class="card-header">Add Product</div>
<div class="card-body">
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary"><i class="fa-solid fa-floppy-disk"></i>Save</button>
</div>
</div>
</EditForm>
</div>
</div>
</div>
@code {
Product MyProduct = new();
public void HandleSaveProduct()
{
}
}
解决方案是将其添加到program.cs
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(AddUpdateProduct).Assembly);
AddUpdateProduct 是客户端组件的名称