Seeking help for a C# ASP.NET Core Web App project

I am trying to add a button click event handler to ASP.NET Core Web App but I am not sure of how to do that. So far, here is what I have done:-

In Index.cshtml file, I have added the following line of code:

<button type="button" @onclick="Click_Submit_Button">Submit</button>

In the Index.cshtml.cs file, I have added the following code template to represent the event handler:

public void Click_Submit_Button() 
{

}

The name onclick in the Index.cshtml code is giving an error that the name does not exist in the current context. I am thinking that this is not the right name and that if I use the right name to represent the button click event handler, the issue will be resolved. If that is indeed the case, I would like to know the right name for the event handler. If that is not the case and/or there are other issues in what I have done, I would appreciate any help in letting me know how to go about resolving the issues and adding the button click event handler correctly.

Answer

The below piece of code shows if you click on the client-side and do action on the client-side

<button name="button" onClick="check()">Click</button>

<script>
function onClick()
{

}
</script>

In onClick function use ajax call and fetch data from server side, without refreshing web page. For reference Ajax Introduction

Leave a Reply

Your email address will not be published. Required fields are marked *