0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

checkboxes and textboxes are both generated at run time and could be one or 20. otherwise i could have done it easily.
you can dynamically assign name and id also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.