【发布时间】:2020-11-06 13:58:51
【问题描述】:
我正在编写小型客户端 Blazor 应用程序。为了避免使用任何数据库(并为其创建整个 API),因为我基本上只有一个单一类对象的列表,我想使用 json 文件。
我知道我可以从文件中读取:
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
但是当我修改这个“预测”列表并尝试做这样的事情时:
await Http.PostAsJsonAsync("sample-data/weather.json", forecasts);
或者
await Http.PostAsJsonAsync<WeatherForecast[]>("sample-data/weather.json", forecasts);
它不保存更改。我检查了浏览器,它正在使用正确的数据进行 POST,但收到 404 作为回报。这样的数据修改后可以保存吗?
【问题讨论】:
-
客户端应用?不-您不能轻松地将文件写入服务器。您必须添加一个 API 并调用它...
标签: c# json blazor blazor-client-side