【发布时间】:2021-02-27 16:50:55
【问题描述】:
我正在从 asp.net mvc 切换到 blazor webassembly。
在 mvc 中,当我需要向控制器发布内容时,我使用的是 jQuery ajax 发布,例如
$.ajax({
method: "post",
type: "post",
contentType: "application/json; charset=utf-8",
url: "../../Tabele/Clone",
traditional: true,
data: data,
success: function (data, status, xhr) {
logujError (data.msg)
},
error: function (xhr) {
console.log("puko si kod postajExtraDetalje", xhr.responseText); //,xhr.statusText,
}
});
现在在 blazor 中我需要发布我正在使用 HttpClient 的数据,例如
var response = await Http.PostAsJsonAsync<ConfigView>($"/api/Vage/Cofnig", configView);
if (response.IsSuccessStatusCode)
{
var data= await response.Content.ReadFromJsonAsync<PocoMsgId>();
logujError (data.msg)
}
else {
// handel error
}
我是否正确理解 C# 和异步方法,因为我在等待两次,所以我的 gui 被冻结直到帖子结束? 如何在 blazor webassembly 中使用 Http 客户端在 gui 中发布数据和显示结果,而不会在发布数据和等待结果期间冻结 guid?
【问题讨论】:
-
您可以毫无问题地等待任意多次
-
@Nick 你能再回答一次吗,我不知道我是如何设法提出 2 个相同的问题的,你回答的一个被删除了
-
大量Json反序列化慢
标签: async-await http-post blazor blazor-webassembly