0

How to handle events such as button onclick(),Select item change etc. in .net core Razor pages web app?

is Javascript/typescript the only way ? [If Yes, I am looking for Typescript sample for this.]

I want to populate a no. of select list (dropdowns) based on selection made in one of the dropdown i.e. Cascading DropDowns.

any help is appreciated.

user7250374
  • 71
  • 1
  • 10

2 Answers2

0

yes you can only have javascript, i suggest you JQuery, you will find a lot of samples on cascading dropdown like here: How to populate a cascading Dropdown with JQuery

jcq
  • 167
  • 2
  • 13
0

You can handle events by implementing event handlers in your razor code behind file. For example. This is a button in my test razor page

<form asp-page-handler="PendTop" method="post">
    <button class="btn btn-default">Edit</button>
</form>

Notice the attribute "asp-page-handler" this is an attribute that comes with the razor technology. You assign the name of your EventHandler to execute with this attribute. In my case it is PendTop.

There is a naming convention that is used within the razor framework when calling your EventHandler. Its based on prepending the letters 'On' before the name of the method.

So for my Event handler I have the method

public void OnPostPendTop(string query)
{

}

Using this will allow you to specify the event handler to be executed in a razor page code behind file. In this scenario the parameter name "query" will be null because I have not specified any parameter value to be sent, but you can change that.

TChaka
  • 1