How can I link a button click to a method on Razor pages, am using ASP.NET Core 6?
I have this bit of code from a razor pages Test.cshtml
<Button>Do some stuff</Button>
and I want to link it to this method from Test.cshtml.cs
public void SomeStuff() { //Some C# code }
I know how to do it if it was a post form but is there any other way to invoke that method?
Trying to link a button click event from a cshtml razor pagee to a function in a cshtml.cs file
2
Answers
Can you use this way ?
Wrap the anchor tag element in the button element and is able to navigate to the specified page method when the button was clicked.
Index.cshtml.cs:
can you try this way ?