c# - How to update HREF after anchor gets clicked in Blazor?
问题描述
Trying to replace HREF upon click on Anchor with Blazor.
So in pseudo;
click => calls function => replaces HREF => triggers open event, but targets new HREF
couldn't make it happen, what should be the syntax?
<a href="javascript: void(0)" @onclick="@(()=> GetCloudFileSignedUrl(context.FileName))">@context.FileName</a>
Side note
Please do not reference https://github.com/aspnet/AspNetCore/issues/5545. I'm asking how to replace the HREF value with an external address which is irrelevant to that issue since I'm OK to use javascript: void(0)
at this point.
解决方案
感谢@daniherrera,我开始寻找正确的地方并在这里找到答案
[Inject] public NavigationManager NavigationManager { get; set; }
[Inject] public IJSRuntime JsRuntime { get; set; }
public async Task NavigateToUrlAsync(string url, bool openInNewTab)
{
if (openInNewTab)
{
await JsRuntime.InvokeAsync<object>("open", url, "_blank");
}
else
{
NavigationManager.NavigateTo(url);
}
}
推荐阅读
- html - ie11 在输入文本字段中按 [Enter] 会导致文本换行
- wpf - 使用元素语法在 UserControl 上设置附加属性值
- amazon-web-services - Amazon aws websocket api - 禁止发送消息
- grafana - 在 Grafana 中将标签添加到仪表板
- python - 拆分返回不匹配
- c - 扫描数字并将它们添加到列表和扫描答案并将其添加到变量
- makefile - makefile:多个自动变量
- python - 熊猫根据其他专栏“切”
- node.js - 使用 bash 在 Windows 上安装节点
- c++ - 如何使用 GetTokenInformation () 恢复权限?C++