ASP.NET MVC. Hot to guess autogenerated id value ?
- by Andrew Florko
My web form contains list of dynamic fields that are generated like this:
<% for (int i = 0; i < Model.Options.Count; i++) { %>
...
<%= Html.Hidden("Options[" + i + "].Id", Model.Options[i].Id)%>
<%= Html.CheckBox("Options[" + i + "].Selected", Model.Options[i].Selected)%>
...
This maps perfectly on array of controller method parameters as described in Model Binding To A List article.
I want to add label for checkboxes to title them, but I have to guess their ids in hmtl layout.
Options[" + i + "].Selected turns into Options_0__Selected
How can I avoid hardcoding Id generation in-built asp.net mvc rules?
Thank you advance.