How can I set the tabindex value of a set of checkboxes within a foreach loop in ASP.NET MVC?
My current solution uses a Response.Write to output the checkboxes, but I'd rather find something more elegant.
Does anyone have a good solution?
This code does not work:
<label for="country">
Country:
</label>
<%= Html.DropDownList("country", Model.Countries.OrderBy(x => x.Text), "Choose country...", new { tabindex = 8 })%><br />
<fieldset id="sales-processing-methodologies">
<legend>Sales Processing Methodology:</legend>
<% int i = 9;
foreach (var method in Model.ProcessingMethodologies)
{
%>
<input type="checkbox" id="<%=method.Key%>" name="processing-methodologies" class="checkbox" value="<%=method.Key%>" tabindex="<%i.ToString();%>"> </input>
<label for="<%=method.Key%>">
<%=method.Value%>
</label>
<% i++;
} %>
</fieldset>
This does:
<label for="country">
Country:
</label>
<%= Html.DropDownList("country", Model.Countries.OrderBy(x => x.Text), "Choose country...", new { tabindex = 8 })%><br />
<fieldset id="sales-processing-methodologies">
<legend>Sales Processing Methodology:</legend>
<% int i = 9;
foreach (var method in Model.ProcessingMethodologies)
{
Response.Write(@"<input type=""checkbox"" id=""" + method.Key + @""" name=""processing-methodologies"" class=""checkbox"" value=""" + method.Key + @""" tabindex=""" + i.ToString() + @"""> </input><label for=""" + method.Key + @""">" + method.Value + @"</label>");
i++;
} %>
</fieldset>
Edit: The code that wasn't working produced tabindex="".