I have a .NET MVC project wherein I have multiple radio buttons in a view that's binded to a unique item in my SQL table. This is a code block in my View page that generates two radio buttons for each row.
@foreach(var item in Model){
@Html.RadioButton(item.ReviewID, "Retain")Retain  
@Html.RadioButton(item.ReviewID, "False")Remove
}
Below the whole list, I have a two buttons that I'm trying to work on that will tick all of the corresponding Radio Buttons.
<input type="button" value="Retain All" onclick="retainAll()" />
<input type="button" value="Retain All" onclick="removeAll()" />
im trying to call these two helpers I declared in my View:
@helper retainAll()
{
foreach (var item in Model)
{
@Html.RadioButton(item.ReviewID, "Retain", isChecked: true);
}
}
@helper removeAll()
{
foreach (var item in Model)
{
@Html.RadioButton(item.ReviewID, "Remove", isChecked: true);
}
}
When I try to click any of the buttons though, it doesn't do anything. This is what it looks like in my View:
https://i.stack.imgur.com/PC0B9.jpg
Take note that the save changes button there works. When clicked, it updates the SQL database with the radio button clicked.
The idea with the "Retain All" and "Remove All" buttons is just to tick all of the radio buttons with Retain or Remove.
**Again, I'm not asking on how to post back the values of the radio button to my sql table. Just asking if there's a way where if I click the "Retain All" or "Remove All" button in the view, it will tick all of the Corresponding radio buttons in the view.(set their 'isChecked' attributes to true)
Deleted the helper code block in my view and replaced it with this:
<script>
function retainAll()
{
@foreach (var item in Model)
{
@Html.RadioButton("rbResponse" + item.ReviewItemID.ToString(), "Retain", isChecked: true);
}
}
function removeAll()
{
@foreach (var item in Model)
{
@Html.RadioButton("rbResponse" + item.ReviewItemID.ToString(), "Remove", isChecked: true);
}
}
</script>