public class Foo { public bool Checked {get;set;}}
View:
<viewdata model="Foo[] fooList" />
<for each="var f in fooList">
${Html.CheckBoxFor(x=>x[fIndex].Checked)}
</for>
Will output:
<input id="Checked" name="Checked" type="checkbox" value="true" />
<input name="Checked" type="hidden" value="false" />
<input id="Checked" name="Checked" type="checkbox" value="true" />
<input name="Checked" type="hidden" value="false" />
<input id="Checked" name="Checked" type="checkbox" value="true" />
<input name="Checked" type="hidden" value="false" />
Problem is that System.Web.Mvc.ExpressionHelper.GetExpressionText
does not include index in id/name.
That leads to problems in case I want to add a label for every checkbox (because all id`s are the same).
Any ideas how to handle this properly?
From the MVC source=>
while (part != null) {
if (part.NodeType == System.Linq.Expressions.ExpressionType.MemberAccess) {
MemberExpression memberExpressionPart = (MemberExpression)part;
nameParts.Push(memberExpressionPart.Member.Name);
part = memberExpressionPart.Expression;
}
else {
//arghhhh... [index] != MemberAccess :(
break;
}
}