Blazor 服务器端在 IIS 上提交表单

kav*_*382 1 forms iis-7.5 blazor-server-side

我有一个带有表单提交的 Blazor 服务器端项目:

        <EditForm Model="@myWebUserVM" OnValidSubmit="HandleValidSubmit">
            <DataAnnotationsValidator />
            <ValidationSummary />
            @if (IsPasswordIncorrect)
            {<h6 class="text-danger">User Name or Password is incorrect.</h6>}
            <div class="row">
                <label class="col-md-4">User Name:</label>
                <div class="col-md-8">
                    <InputText id="uname" class="form-control" placeholder="User Name" @bind-Value="myWebUserVM.UserName" />
                </div>
            </div>
            <div class="row my-3">
                <label class="col-md-4">Password:</label>
                <div class="col-md-8">
                    <InputText id="upassword" class="form-control" type="password" placeholder="Password" @bind-Value="myWebUserVM.Password" />
                </div>
            </div>
            <div class="text-center">
                <button class="btn btn-outline-success" type="submit">Login</button>
            </div>
        </EditForm>
Run Code Online (Sandbox Code Playgroud)

当我在 VS2019 本地运行它时,效果非常好。当我发布到 IIS 时,表单的工作方式有所不同。点击提交按钮将 http post 到服务器,页面/表单将重新加载。所以看起来我只是第一次打开它或在浏览器中按 F5。“private void HandleValidSubmit()”中的代码不会命中。看起来我只是用 HTTP 发布了一个常规表单。但这是一个 SPA,我不需要它通过 HTTP 发布。带验证的 Blazor 表单的正确代码应该是什么?为什么在VS2019调试模式下可以工作?或者,最有可能的是,需要 IIS 设置?谢谢。

kav*_*382 5

我已经找到了这个的原因。在 Firefox 和 Chrome 控制台中,错误为 Error: Found malformed component comment at Blazor:{"sequence":0,"type":"server","prerenderId"... 并且仅 MS Edge 显示 HTML 中有两个 BODY 元素。这两个会导致 blazor.js 中出现错误。第二个 BODY 来自 MainLayout.razor 中的 TelerikRootComponent。因此删除第二个 BODY 解决了问题。我还是不明白为什么在VS2019中运行得很好。开发人员不应忽略此 Blazor 错误“在 Blazor 中发现格式错误的组件注释”。MS Edge 也不应该被忽视:-)