I have the following radio button in my view. How can I pass the value of the selected radio button and values in an array index less than the selected radio button?.
foreach (var record in Model.Months.Select(x=>$"{x.Substring(4,2)}/{x.Substring(0,4)}").OrderByDescending(x=>x))
{
<div class="radio col-12">
<div class="row">
<div class="col-5" style="">
@Html.RadioButton("MonthsAvailable", record, true, new { id = record, @class = "m-r" })<label>@record</label>
</div>
</div>
</div>
}
HTML Generated Code
<div class="row">
<label class="form-check-inline p-l-md m-b-sm m-r-md">
<input class="hidden-up pos-abs monthsAvailable" id="082020" name="MonthsAvailable" type="radio" value="202008" checked="checked">
<div class="check-icon-radio"><i></i></div>
082020
</label>
</div>
<div class="row">
<label class="form-check-inline p-l-md m-b-sm m-r-md">
<input class="hidden-up pos-abs monthsAvailable" id="092020" name="MonthsAvailable" type="radio" value="092020">
<div class="check-icon-radio"><i></i></div>
092020
</label>
</div>
My Model
public class MonthsAvailable
{
public List<string> Months{ get; set; }
}
My Action Receives
public async Task<IActionResult> MonthsAvailable(List<string> monthsAvailable)
{
...
}
My radio button looks like as follows
I am trying to accomplish
When I select 062020 pass only 062020 to the controller,
When I select 072020 pass 062020 and 072020,
when I select 082020 pass 062020, 072020 and 082020
when I select 092020 pass 062020, 072020, 082020 and 092020 and etc