Blazor 页面的 URL 正在干扰组件对 API 的调用 -- 400-Bad Request

Blazor page's URL is interfering with component's call to API -- 400-Bad Request

我的网络应用程序是 .Net 6,VS-2022 Blazor WASM 托管。

从组件调用时,API 的 URL 出现问题。 我有三个文件:页面:VehicleList.razor、页面:VehicleEdit.Razor 和组件:CRUD_Vehicle.razor.

页面流是用户导航到 'VehicleList' 并且能够通过回调函数 select 编辑车辆。 selected 后,流程导航到 'VehicleEdit',其中需要传递一些数据以支持嵌入式子组件 'CRUD_Vehicle'。

问题是 URL 到 'VehicleEdit' 看起来像这样,查询字符串数据在逗号分隔的字符串中,并且在显示 CRUD 组件时它仍然存在。

https://localhost:7777/vehicleedit/667?par=17,Bigelow,Active

当用户进行编辑更改并提交组件时,HttpClient 服务被调用并失败并返回 400-Bad Request。我的印象是查询字符串会干扰 api URL。请看下面。有没有一种方法可以将 URL 设置为不显示查询字符串,只显示基地址和这样的 UID_VEHICLE?

https://localhost:7777/vehicleedit/667

public async Task<Vehicle> UpdateVehicle(Vehicle pVehicle) {
    // Save the edited record.
    HttpResponseMessage response = await httpClient.PutAsJsonAsync<Vehicle>($"/api/vehicle/{pVehicle.UID_VEHICLE}", pVehicle);
    if (!response.IsSuccessStatusCode) {
        // problems handling here.
        Console.WriteLine($"UpdateVehicle() Error occurred, the status code is: {(int)response.StatusCode}: {response.StatusCode}" );
    }
    return await response.Content.ReadFromJsonAsync<Vehicle>();
}

我对 Customer 对象的编辑有一个类似的构造,但是显示 CRUD_Customer 组件的页面有一个简单的 URL 并且可以完美地将数据保存到数据库中。主要区别在于 URL 与 VehicleEdit.razor。欢迎您提出意见。 谢谢。

https://localhost:7777/customeredit/17

我下载了 Postman 并输入了 PUT 事务,PUT 结果显示有一个错误(基于 'StartDate' 字段的 DataAnnotation)未在客户端验证代码中捕获。事实证明,TITLE 文本是基于可能的原因。但是 Postman 向我展示了 PUT 调用失败的确切原因。

所以,我的 'answer' 是:使用 Postman 模拟 'httpClient.PutAsJsonAsync'-call 来观察 result-details 以查明“400-Bad Request”的原因 return 来自服务。