htmlasp.net-mvcasp.net-mvc-4razorstrongly-typed-view

@Html.CheckBoxListFor, setting the tab index for each checkbox?


3rd Party Component: MvcCheckBoxList

I have this strongly typed lists of check-boxes, I just want to set their tab index. How can i do this?

   @Html.CheckBoxListFor(model=>model.agentTypeViewModel.PostedAgentTypes.AgentTypeId,
                                                          model=>model.agentTypeViewModel.AvailableAgentTypes,
                                                          agent=>agent.Id,
                                                          agent=>agent.Name,
                                                          model=>model.agentTypeViewModel.SelectedAgentTypes,
                                                          Position.Vertical)

I was successfully able to set my other controls tab-index, @Html.TextBoxFor(p=>p.TRU, new {tabindex = 28, id="txtTRU"}) works fine; but apparently if I don't set a tab-index for the check-boxes, pressing tab will directly move cursor to the list of check-boxes, completely ignoring all other 26 fields that come first...

Any suggestions?


Solution

  • It looks like you're using the MvcCheckBoxList component. According to the documentation (not sure why you didn't bother to read this):

    MvcCheckBoxList

    You would just do this:

    @Html.CheckBoxListFor(model => model.agentTypeViewModel.PostedAgentTypes.AgentTypeId,
                          model => model.agentTypeViewModel.AvailableAgentTypes,
                          agent => agent.Id,
                          agent => agent.Name,
                          model => model.agentTypeViewModel.SelectedAgentTypes,
                          Position.Vertical,
                          x => new {tabindex = 28})