Hi,@Russell Sharp ,
The RadioButton group is used to choose one of a list of predefined values for one of the fields(in the same way as dropdown list would do so).
If you mean you only want to pass selected value of radio button to handler,you don't need to add the selected value to field when clicking the radio button.
When you select a radio button,and post it with form,the selected value will be sent by default.Here is a working demo:
Model:
public class Person
{
public string Gender { get; set; }
}
cshtml(.net core bind data with name attribute):
<form method="post">
<input type="radio" name="Gender" value="Male" />Male<br />
<input type="radio" name="Gender" value="Female" />Female<br />
<input type="radio" name="Gender" value="Unspecified" />Unspecified<br />
<input type="submit" value="submit" />
</form>
cshtml.cs:
[BindProperty]
public Person person { get; set; }
public void OnGet()
{
}
public void OnPost()
{
}
result:
----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
YiyiYou