Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to get and set values from radio buttons to backend

$
0
0

I have a question form where users can answer one out of four answers. I use the custom bootstrap4 radio buttons like so:

What's your favourite number?

<form asp-controller="Test" asp-action="TestPost" method="post"> <div class="form-group"> <div class="custom-control custom-radio custom-control-inline"><input type="radio" id="custom1" name="Question1" class="custom-control-input" /></div><div class="custom-control custom-radio custom-control-inline"><input type="radio" id="custom10" name="Question1" class="custom-control-input" /></div> <div class="custom-control custom-radio custom-control-inline"><input type="radio" id="custom11" name="Question1" class="custom-control-input" /></div> <div class="custom-control custom-radio custom-control-inline"><input type="radio" id="custom12" name="Question1" class="custom-control-input" /></div> </div>

<button class="btn btn-primary" type="submit">Next</button>

But it seems like every button is "on" or "off", like a boolean. I want the number corresponding to the radio button to be sent to the controller. Ideally I try to have a property on the viewmodel for each question(not each radio button). So if I have a property like int Question1, then the value would be set depending on what button is ticked. But I can't seem to do it and it's frustrating, hahaha. 

Any ideas?

</form>

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>