I am new to RAZOR, I want to trigger an event when a user clicks on the RadioButton.
Ideally, it should dynamically show the selected value after a user clicked a RadioButton.
Questions:
-
How to get the selected value
-
How to trigger an event when a user clicked a RadioButton.
@{ Layout = "~/_SiteLayout.cshtml"; Page.Title = "Contact"; } <div> <table> <tr> <td> @Html.RadioButton("Gender", "Male", true) Male </td> <td> @Html.RadioButton("Gender", "Female", false) Female </td> </tr> </table> @Html.Label(Request["Gender"] == null ? "No Selection" : Request["Gender"])
You can not do it with Razor, What you can do is to Create Radio Button Like this and Trigger any Action using Jquery.
You could add script (assuming you can use jQuery) on the page like:
Assuming you have an action method in the same controller as the one that generated your view: