Baahubali
Baahubali

Reputation: 4802

ASP.NET MVC Checkbox with Textboxes

i have written this code in one of the view using ASP.NET MVC. MVC returns me the checkboxes values (only those are checked) and with textboxes it returns me all (0,1,2 etc). how can i co-relate which textbox value belongs to which checkbox (since only i get the checked checkbox values)

   For Each item As InternalMailCalendarViewModel  In ViewData("InternalMailCalendar")

        End Code    
             <div class="editor-field">
                @Html.CheckBox("InternalMailCalendarID", New With {.value = item.ID})
                 <label for="@item.ID">@item.Days</label>
             </div>
             <div class="editor-field">
                 <input type="text" id="RunsPerDay" name="RunsPerDay" placeholder="Runs Per Day" />
                 @Html.ValidationMessageFor(Function(model) model.RunsPerDay)
             </div>
            @*   
            <div class="editor-field">
                <input type="checkbox" id="InternalMailCalendarID" name="InternalMailCalendarID" value="@item.ID" />
                 <label for="@item.ID">@item.Days</label>
             </div>
             <div class="editor-field">
                 <input type="text" id="RunsPerDay" name="RunsPerDay" placeholder="Runs Per Day" />
                 @Html.ValidationMessageFor(Function(model) model.RunsPerDay)
             </div>
           *@

         @Code   

        Next
        End Code

Upvotes: 0

Views: 896

Answers (1)

rishikesh tadaka
rishikesh tadaka

Reputation: 483

According to my understanding of your code and problem, I suggest you following solution:

Just assign hmtl "Name" property to textbox uniquely and that unique name assign to checkbox as a value. So that you can co-relate textbox with checkbox.

Upvotes: 1

Related Questions