Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update href after anchor gets clicked in Blazor? #15200

Closed
cilerler opened this issue Oct 20, 2019 · 1 comment
Closed

How to update href after anchor gets clicked in Blazor? #15200

cilerler opened this issue Oct 20, 2019 · 1 comment

Comments

@cilerler
Copy link

cilerler commented Oct 20, 2019

How can I replace the href value of <a> from a function's result?

If I write it like below, it calls the function without waiting for the click.

<a href="@GetCloudFileSignedUrl(context.FileName)">@context.FileName</a>

I changed it like below, but still no luck.

<a href="javascript: void(0)" @onclick="@(()=> GetCloudFileSignedUrl(context.FileName))">@context.FileName</a>

I'm already aware of #5545, and I believe my question is slightly different.

@cilerler cilerler changed the title How to update HREF after anchor gets clicked in Blazor? How to update href after anchor gets clicked in Blazor? Oct 20, 2019
@cilerler
Copy link
Author

Found the answer here #8703

        [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);
            }
        }

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant