Open octavian-cacina-gotomaxx opened 10 months ago
Thanks for contacting us! Could you please try removing href="#"
and @onclick:preventDefault
<a @onclick="IncrementCount">Click me</a>
and se if it works?
Thanks for contacting us.
We're moving this issue to the .NET 9 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Could you please try removing
href="#"
and@onclick:preventDefault
<a @onclick="IncrementCount">Click me</a>
and se if it works?
I have tried, but then the element is not clickable, and the handler ist not called.
I encountered a similar issue.
My objective was to create an anchor tag with an href attribute, allowing users to right-click and open the link in a new tab. Concurrently, I aimed to implement some sophisticated logic upon clicking. To achieve this, I needed the capability to prevent the default action while simultaneously detecting a click event in C#.
Ultimately, I resolved the issue as follows:
r.OpenElement(0, "a");
r.AddAttribute(1, "href", _navigation.Url);
r.AddAttribute(2, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, OnClicked));
r.AddAttribute(3, "onclick", "return false;");
...
This solution effectively accomplished the following:
I used ChatGPT to improve the readability of this comment
Thanks for contacting us.
We're moving this issue to the .NET 9 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
I have @rendermode InteractiveServer
and it's not working with it either.
Is there an existing issue for this?
Describe the bug
<a href="#" @onclick="IncrementCount" @onclick:preventDefault>Click me</a>
it is not preventing the default handling in a Blazor App with Auto interactivity, even if the page is properly configured for WebAssembly. If the App is created only with WebAssembly interactivity, it works as expected.
50992 is similar, but it does not indicate any resolution.
Expected Behavior
preventDefault should prevent any further navigation
Steps To Reproduce
<a href="#" @onclick="IncrementCount" @onclick:preventDefault>Click me</a>
@rendermode InteractiveAuto
or@rendermode InteractiveWebAssembly
, clicking on the link triggers the default navigation to home. preventDefault should have stopped this.Exceptions (if any)
If the Blazor App is created only with WebAssembly interactivity, it works as expected.
.NET Version
8.0.100
Anything else?
No response