Hello
I have a loop, where I need to use the values from 2 IEnumerable's, and I need to get the current index and value for "labels", so I can print out labelname for each one.
public static string CheckBoxList(this HtmlHelper htmlhelper, IEnumerable<string> values, IEnumerable<string> labels, string name, IDictionary<string, object> HtmlAttributes)
{
if (labels == null)
return "";
StringBuilder sb = new StringBuilder();
string[] modelValues = new string[] {};
ModelState modelState;
if(htmlhelper.ViewData.ModelState.TryGetValue(name, out modelState)) {
modelValues = ((string[])modelState.Value.RawValue);
}
foreach(string s in values)
{
bool isChecked = modelValues.Contains(s);
sb.Append(CreateCheckBox(name, s, isChecked, HtmlAttributes));
sb.Append(" <label for=\"" + name + "\"> " + labels + "</label><br />");
}
return sb.ToString();
}
How can I print out current value for "labels" in that loop? Also I need the "index", need to build a unique ID for checkbox so label will work.
Thanks in advance. /M