ASP.NET MVC. Hot to guess autogenerated id value ?
Posted
by Andrew Florko
on Stack Overflow
See other posts from Stack Overflow
or by Andrew Florko
Published on 2010-05-20T11:19:19Z
Indexed on
2010/05/20
11:20 UTC
Read the original article
Hit count: 247
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.
© Stack Overflow or respective owner