Validate Radio Button JavaScript + MVC Razor

1

I need to validate if all of my Radio has been checked, can you help me validate this in JS? My cshtml is mounting the radio's through a List < > of the Model.

<div id="checklists" class="row">
        <div class="col-md-6">
            @{int index = 0; }
            @foreach (var descricao in @Model.Domiciliacao.listaPerg)
            {
                <div class="descricaoItemChecklist" style="height: 40px;">
                    <table class="table table-striped" width="100%" id="tbListaPerg">
                        <tbody>
                            <tr>
                                <td width="80%">@descricao.descperg</td>
                                <td width="10%">
                                    <label class="CheckBox-inline">
                                        @Html.RadioButtonFor(m => m.Domiciliacao.listaPerg[index].ckPerg, true, new { @class = "radio-inline", @id = "rbListaPerg" }) Sim
                                    </label>
                                    @Html.HiddenFor(m => m.Domiciliacao.listaPerg[index].codperg)
                                    @Html.HiddenFor(m => m.Domiciliacao.listaPerg[index].descperg)
                                </td>
                                <td width="10%">
                                    <label class="CheckBox-inline">
                                        @Html.RadioButtonFor(m => (m.Domiciliacao.listaPerg[index].ckPerg), false, new { @class = "radio-inline", @id = "rbListaPerg" }) Não
                                    </label>
                                    @Html.HiddenFor(m => m.Domiciliacao.listaPerg[index].codperg)
                                    @Html.HiddenFor(m => m.Domiciliacao.listaPerg[index].descperg)
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>  
                index = index + 1;
            }
        </div>
    </div>
    
asked by anonymous 26.10.2017 / 16:01

1 answer

0

I was able to resolve by checking yes and creating validation for Yes or No.

 @Html.RadioButtonFor(m => m.Domiciliacao.listaPerg[index].ckPerg, true, new { @class = "radio-inline", @checked = true}) Sim

var check = true;
        $(".validar:input").each(function () {
            if ($(this).prop("type") == "radio") {
                if ($(this).attr("checked") == "True") {
                    if ($(this).val() == "N") {
                        check = false;
                    }
                }
            }
        });
    
26.10.2017 / 19:48