【发布时间】:2022-02-17 14:30:45
【问题描述】:
到目前为止,我在 blazor webassembly/aspnetcore 环境中实现了自定义 uri 方案逻辑。 问题出现在以下情况。
- 单击 blazor 组件中的特定按钮,后端 Api 服务器将使用自定义 uri 方案对此进行响应。
- 无需用户操作即可执行嵌入的 javascript 函数。
- 执行 java 脚本时出错。
我找不到任何相关的解决方案。
[服务器响应]
<!doctype html>
<html lang=\"en\">
<head>
<script src=\"/res/vender/jquery/jquery-3.5.1.min.js\"></script>
<script type=\"text/javascript\">
$(document).ready(function() {
RunRestBuilder(
}
</script>
<script language=\"JavaScript\" type=\"text/javascript\">
function RunRestBuilder()
{location.href="APIRunner://runmode:0;username:pink;password:xxx;project:myproject;id:
{1};testcase:{test};testtype:{1};";
}
</script>
</head>
<body>
<a href="#"onclick=\"RunRestBuilder(\">Execute</a>
</body>
</html>
[blazor 服务]
public async Task<string> Edit(string id, string testCase, string testType)
{
var queryStringParam = new Dictionary<string, string>
{
["projectName"] = await _localStorage.GetItemAsync<string>
("projectName"),
["id"] = id,
["testCase"] = testCase ?? string.Empty,
["testType"] = testType};
using (var response = await
_client.GetAsync(QueryHelpers.AddQueryString("restbuilder/edit",
queryStringParam)))
{
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync();
_snackbar.Add($"error occured. errorMessage:{error}",
Severity.Error);
return string.Empty;
}
var result = await response.Content.ReadAsStringAsync();
return result;
}
}
[blazor 组件]
await RestBuilderService.Edit(id, testCase, testType);
await Js.InvokeVoidAsync("RunRestBuilder");
[错误信息] '找不到'RunRestBuilder'('RunRestBuilder'未定义)。错误:找不到'RestBuilder'('RestBuilder'未定义)。 在 http://localhost:5002/_framework/blazor.webassembly.js:1:1287 在 Array.forEach ()\n 在 e.findFunction (http://localhost:5002/_framework/blazor.webassembly.js:1:1247) 在 b (http://localhost:5002/_framework/blazor.webassembly.js:1:2989) 在 http://localhost:5002/_framework/blazor.webassembly.js:1:3935 在新的承诺 () 在 Object.beginInvokeJSFromDotNet (http://localhost:5002/_framework/blazor.webassembly.js:1:3908) 在 Object.w [as invokeJSFromDotNet] (http://localhost:5002/_framework/blazor.webassembly.js:1:64232) 在 _mono_wasm_invoke_js_blazor (http://localhost:5002/_framework/dotnet.5.0.13.js:1:190800) 在 do_icall (wasm://wasm/00aba242:wasm-function[10596]:0x194e4e)'
【问题讨论】:
标签: blazor blazor-server-side blazor-webassembly