mardi 15 septembre 2015

Get CheckBox value in a foreach loop

I have a Model with OtherCountries as a List. Before each Country I need to put a checkbox:

@foreach (string country in Model.OtherCountries)
    {
        <div class="form-group">
            <div class="col-md-2 control-label">
                @Translations.Text
            </div>
              <div class="col-md-10">
                <div class="col-md-1">
                    <label>
                        <input type="checkbox" name="checkboxCountry" id="checkboxCountry" value="true"/>
                    </label>
                </div>
                <div class="col-md-11">
              <textarea name="@(Html.NameFor(m => m.OtherCountries))" class="form-control textarea-resize" rows="5">@country</textarea>
              </div>
            </div>
        </div>
    }

With the submit button I can send the Model to a Controller but my problem is that I don't know wich checkbox belongs to wich country? Every country has a checkbox in front of it but If I want for example to delete a country from the list I have to do that based on the checkbox.




Aucun commentaire:

Enregistrer un commentaire